对于前端(角)有一个服务器,后端在Firebase中,我使用的是。
我尝试了数据库实时,一切正常,但我想尝试云修复和它的集合。
问题如下:
这是构成部分:
items: Array<any>;
constructor(private aboutUsService: AboutUsService) { }
ngOnInit() {
this.getData();
}
getData() {
this.aboutUsService.getContent()
.subscribe(data => {
this.items = data;
console.log('items: ', this.items);
}, // Bind to view
err => {
console.log(err);
});
}这是服务:
getContent() {
return this.db.collection('aboutus').snapshotChanges();
}目前,我在Cloud中有一个集合:

规则云修复:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}服务响应并使用元素返回以下数组(这是this.items的内容):
[{…}]
0:
payload: {type: "added", doc: n, oldIndex: -1, newIndex: 0}
type: "added"以下是Chrome网络选项卡中的标题:
Request URL: http://localhost:4200/aboutus
Request Method: GET
Status Code: 304 Not Modified
Remote Address: 127.0.0.1:4200但是我无法找到集合的数据来显示在前端(变量this.items)。
如果我在响应数组中向集合"aboutus“添加元素,则它对应于集合的元素,但无法可视化数据。
有什么问题吗?谢谢
发布于 2020-05-29 14:16:24
正如我在两周前(5月15日)的评论中提到的那样:
您应该使用
AngularFirestoreCollection.valueChanges,它返回集合值的Observable,而AngularFirestoreCollection.snapshotChanges则在快照上显示其他元数据。有关更多信息,请考虑查看文档:https://github.com/angular/angularfire/blob/master/docs/firestore/collections.md
因此,您应该将snapshotChanges调用替换为valueChanges
getContent() {
return this.db.collection('aboutus').valueChanges();
}https://stackoverflow.com/questions/61835629
复制相似问题