我正在遵循一个教程,其中我们填充了一个选择列表。
老师使用的是Angular4,而我使用的是最新版本,所以我认为应用编程接口发生了变化。
我尝试在一个名为CategoryService的类中使用此方法:
getCategories() {return this.db.list('/categories');}
在我的构造函数中的另一个名为ProductFormComponent的类中,我试图返回一个可以在HTML中捕获的可观察对象
categories$;
constructor (
private router: Router,
private categoryService: CategoryService,
private productService: ProductService) {
this.categories$ = categoryService.getCategories();
}
我的HTML如下所示:
<div class="form-group">
<label for="category">Category</label>
<select #category="ngModel" ngModel name="category" id="category" class="form-control" required>
<option value=""></option>
<option *ngFor="let c of categories$ | async" [value]="c.$key">
{{ c.name }}
</option>
</select>
<div class="alert alert-danger" *ngIf="category.touched && category.invalid">
Category is required.
</div>
</div>
这会产生错误
错误: InvalidPipeArgument:管道'AsyncPipe‘的'object Object’
我做错了什么?有什么方法可以解决这个问题?
https://stackoverflow.com/questions/56468575
复制相似问题