我有以下模板:
*ngFor="let contact of contacts | async"
在哪里:
contacts: Observable<any>;
我收到此错误:
ERROR Error: Cannot find a differ supporting object '[object Object]'
of type 'object'. NgFor only supports binding to Iterables such as Arrays.
为什么 ngFor 异步管道需要
Observable<any[]>
而不是 Observable<T>
?
最佳答案
这不是因为 async
管道。contacts
Observable 发出对象而不是数组,并且您不能使用 *ngFor
迭代对象.这就是错误消息所说的。
所以问题出在 contacts
.看看它真正发出了什么。
关于angular - 为什么 ngFor 异步管道需要 Observable<any[]> 而不是 Observable<any>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48346774/