【发布时间】:2021-11-09 17:16:35
【问题描述】:
我已经完美地运行了我的应用程序
"@angular/fire": "^6.1.5",
"@angular/core": "~12.0.2"
就像
服务.ts
getInboxCollection(userId: string) {
return this.firestore.collection(`/user/${userId}/inbox/`).snapshotChanges().pipe(
map(
changes => {
return changes.map(
a => {
const data: any = a.payload.doc.data();
data.id = a.payload.doc['id'];
return data;
});
})
);
}
组件.ts
this.service.getInboxCollection(this.userId).subscribe((res: any) => {
console.log(res);
}
现在我已经迁移到最新版本的 AngularFire
"@angular/fire": "^7.0.4",
新的变化是
service.ts
import { doc as fireDoc, docData, Firestore, docSnapshots } from '@angular/fire/firestore';
getInboxCollection(userId: string) {
const refOfInbox = fireCollection(this.firestore, `/user/${userId}/inbox/`);
return docSnapshots(fireDoc(refOfInbox)).pipe(map(res => {
const data = res.data();
data['id'] = res.id;
return data;
}))
}
组件.ts
this.service.getInboxCollection(this.userId).subscribe((res: any) => {
console.log(res);
}
但我在控制台上变得不确定。
根据此官方文档docSnapshots,数据仅可通过访问 firebasse 文档 获得。
https://github.com/angular/angularfire/blob/master/docs/version-7-upgrade.md
但是如何使用 docSnapshots 或其他实时更改的方法从 firebase 集合 获取数据?
请帮助我找到更好的方法。
提前致谢。
【问题讨论】:
标签: javascript angular firebase google-cloud-firestore angularfire