【发布时间】:2019-09-14 18:20:43
【问题描述】:
**我在显示类别时遇到问题。我正在尝试使用
异步
功能但不显示数据**
<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>
我已经尝试过了,但它不起作用
product-form.component.ts
export class ProductFormComponent {
categories$;
constructor(categoryService: CategoryService) {
this.categories$ = categoryService.getCategories();
}
}
我在这里创建产品数据
save(product) {
this.productService.create(product);
console.log(product);
}
category.service.ts **通过使用
.valueChanges
我能够获取数据,但它没有将数据存储在 firebase db 中。它显示未定义**
export class CategoryService {
constructor(private db: AngularFireDatabase) {}
getCategories() {
return this.db.list('/categories').valueChanges();
}
}
为了创建产品数据并将其推送到数据库中,我使用了这种方法
product.service.ts
export class ProductService {
constructor(private db: AngularFireDatabase) {}
create(product) {
return this.db.list('/products').push(product);
}
}
这是我遇到的错误
InvalidPipeArgument: '[object Object]' 用于管道'AsyncPipe'
【问题讨论】:
标签: html angular typescript