我是angular和firebase的新手,我有一个crud操作项目,其工作方式如下
export class EmployeeService {
employeeList: AngularFireList<any>;
selectedEmployee: Employee = new Employee();
constructor(private firebase: AngularFireDatabase) { }
getData() {
this.employeeList = this.firebase.list('employees');
return this.employeeList;
}
insertEmployee(empoloyee: Employee) {
this.employeeList.push({
name: empoloyee.name,
position: empoloyee.position,
office: empoloyee.office,
salary: empoloyee.salary
});
}
updateEmployee(emp : Employee){
this.employeeList.update(emp.$key,{
name : emp.name,
position : emp.position,
office : emp.office,
salary : emp.salary
})
}
deleteEmployee(key : string){
this.employeeList.remove(key);
}
}
根据我的理解,此处添加了一条新记录,即将项目添加到通过getData获取的列表中。
是否可以在不获取列表的情况下在集合中添加新文档
谢谢
答案 0 :(得分:0)
您没有获取任何数据。
ndarray
是一个列表绑定。仅在将this.firebase.list('employees')
创建的可观察对象中添加valueChanges()
和subscribe()
时才会获取数据