node.js - Angular在没有列表的情况下在firestore中添加新文档
问题描述
我是 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 获取的列表中。
是否可以在不获取列表的情况下在集合中添加新文档
谢谢
解决方案
您没有获取任何数据。
this.firebase.list('employees')
是一个列表绑定。仅当您将valueChanges()
和添加subscribe()
到由valueChanges()
推荐阅读
- arrays - 使用 Matlab 中的 2D 索引数组从 3D 数组中获取值列表
- python - PermissionError:[Errno 13] 权限被拒绝:路径 chromedriver.exe
- rust - 现在不推荐使用`KeyboardInput.modifiers`,如何获取修饰键?
- javascript - 为什么我的 onclick 功能只在第一次点击后才起作用?
- css - 水平堆叠时间线的一致左边距百分比间距
- excel - 在excel中复制最近/最后一张表
- docker - QEMU 客户机上的 Docker 容器没有 LAN 连接
- r - 从 R 表在 Excel 工作簿中创建多个工作表?[使用 xlsx 包]
- reactjs - 如何在反应中使用axios发布标题
- c - GCC 自动对变量和代码段进行分组