angular - 从 firebase 实时数据库中读取数据并使用 Angular 显示为列表
问题描述
我正在尝试通过跟随视频来实现产品列表,但该列表没有显示我在firebase
数据库中列出的产品。有人可以帮忙吗?
产品-form.component.html
<div class="form-group">
<label for ="category">Category</label>
<select id="category" class="form-control">
<option value=""></option>
<option *ngFor="let c of categories$ | async" value="c.$key">
{{ c.name }}
</option>
</select>
</div>
产品-form.component.ts
export class ProductFormComponent implements OnInit {
categories$;
constructor(categoryService: CategoryService) {
this.categories$= categoryService.getCategories();
}
ngOnInit() {
}
}
类别.service.ts
export class CategoryService {
constructor(private db:AngularFireDatabase) { }
getCategories() {
return this.db.list('/categories');
}
}
我已经手动输入了 firebase 实时数据库中的类别,看起来像这样。类别
解决方案
试试这样:
getCategories() {
return this.db.list('/categories').snapshotChanges();
}
推荐阅读
- javascript - onPress={() => this.props.navigation.openDrawer} 没有在 react-native 中显示抽屉导航
- reactjs - 为什么 Ant Design Mobile 中没有提交按钮?
- python-3.x - 任何人都可以解决我的问题我正在尝试在 ubuntu 20.04 中运行 django 服务器但无法运行
- javascript - 验证密码的 Javascript 函数(Coderbyte 编码挑战简单密码)
- python - 是否可以打开一个csv文件并在其中再次打开它?
- python-3.x - 如何在 matplotlib 直方图中设置 y 轴?
- asp.net - Route to Default 页面与已定义的 Route 混合在一起?
- python - Flask - 上传多个文件
- html - 我如何并排浮动共享一个类的这两个元素?
- c - 是 (0.1 + 0.2) == 0.3 对还是错?