【发布时间】:2019-09-08 18:07:45
【问题描述】:
我无意中更改了某处的一些代码,现在我的帖子不再被拉出,有人能发现错误吗?
服务:
posts: AngularFirestoreCollection<any[]>;
constructor(private db: AngularFirestore) { }
getPosts() {
this.posts = this.db.collection('/posts') as AngularFirestoreCollection<any[]>;
return this.posts;
}
}
帖子组件:
posts: AngularFirestoreCollection<any>;
constructor(private firebaseService: FirebaseService) { }
ngOnInit() {
this.posts = this.firebaseService.getPosts();
}
}
发布 HTML:
<mat-grid-tile *ngFor="let post of posts">
<mat-card class="mat-elevation-z4">
<img mat-card-image src="{{post.imgUrl}}">
<mat-card-actions>
<button mat-icon-button><mat-icon>thumb_up_alt</mat-icon></button><span class="counter mat-small">{{post.numberOfLikes}}</span>
<button mat-icon-button><mat-icon>star</mat-icon></button><span mat-small class="counter mat-small">{{post.numberOfSaves}}</span>
</mat-card-actions>
</mat-card>
</mat-grid-tile>
</mat-grid-list>``
现在我收到Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
【问题讨论】:
-
试试
*ngFor="let post of posts | async" -
谢谢,但现在我明白了。
InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe' -
-
你能显示来自
this.db.collection('/posts') as AngularFirestoreCollection<any[]>的回复吗? -
根据以下答案中的 OP 问题和 cmets,确定他得到的是对象而不是数组。这就是您收到
ngfor only supports binding to iterables的原因。检查服务调用的响应和posts的内容以解决问题
标签: angular typescript firebase google-cloud-firestore angularfire2