[英]Cannot populate dropdown with firebase data
I trying to populate a dropdown with my firebase data.我试图用我的 firebase 数据填充下拉列表。 I am using angular 9.1.9.
我正在使用 angular 9.1.9。 Please assist.
请协助。
category.service.ts类别.service.ts
constructor(private db: AngularFireDatabase) { }
getCategories() {
return this.db.list('/categories', (ref) => ref.orderByChild('name'))
.snapshotChanges()
.pipe(
map((actions) => {
return actions.map((action) => ({
key: action.key,
val: action.payload.val(),
}));
})
);
}
product-form.component.html产品-form.component.html
<select [ngModel] id="category" class="form-control">
<option value=""></option>
<option *ngFor="let c of categories$ | async" [value]="c.key">
{{c.payload.val().name}}
</option>
</select>
products-form-component.ts产品-form-component.ts
export class ProductFormComponent implements OnInit {
categories$;
constructor(categoryService: CategoryService) {
this.categories$ = categoryService.getCategories();
}
{{c.val.name}}
would help as your val
object already contained payload.val()
, just need to access name
property from it. {{c.val.name}}
会有所帮助,因为您的val
object 已经包含 payload.val payload.val()
,只需要从中访问name
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.