【发布时间】:2021-09-02 15:34:24
【问题描述】:
这里我需要检索文档数据和文档 ID 以显示相关的帖子数据。但是我没有找到更好的方法来做到这一点。请帮帮我。
public postId: string;
public posts: any = [];
this.postService.getRecentFivePosts().subscribe((res1) => {
console.log(res1);
});
getRecentFivePosts() {
return this.firestore.collection('Post', ref => ref.orderBy('date', 'desc').limit(5)).snapshotChanges();
}
【问题讨论】:
-
“我没有找到更好的方法”你目前的代码有什么问题?
-
不知道怎么从res1中获取文档数据和id。
标签: javascript angular firebase google-cloud-firestore angularfire2