【问题标题】:Refreshing data from FireStore GET subscription- Angular - Firebase/FireStore从 FireStore GET 订阅刷新数据 - Angular - Firebase/FireStore
【发布时间】:2020-07-03 09:26:59
【问题描述】:

我正在订阅 Firestore 的文档“this.afs.collection('messaging').doc(email);”它位于 NgOnInit() 中。在 Firestore 中创建另一个文档后,我想刷新数据。我对做到这一点的最佳方法有点困惑。我已经尝试过“window.location.reload()”,但我的 POST 操作没有完成。我也尝试过使用 changeDetector 也没有帮助。

组件

ngOnInit(){
const doc = this.afs.collection('messaging').doc(email);
doc.subscribe( usersData => { this.users = usersData });

`

`

模板

<ng-container *ngFor="let user of users;index as i">
{{user.payload.doc.data().displayName}}
</ng-container>

`

【问题讨论】:

    标签: angular firebase google-cloud-firestore rxjs ionic4


    【解决方案1】:

    根据我假设您使用@angular/fire 的模式。另外,您在这里处理的是幕后的 websocket,这意味着这里发生的一切都是实时发生的。这意味着,您不必刷新任何内容。

    【讨论】:

    • 不正确。当我发布新数据时,我的数据没有更新。 this.afs.collection('messaging').doc(senderEmail).collection(messages-${receiverEmail}).add({ messages: dataArg.messages, });
    • 您不是在更新电子邮件文档,而是在您没有订阅的子集合中创建一个新文档..
    • 我在第二行订阅了“doc.subscribe()”
    猜你喜欢
    • 2020-04-07
    • 2020-01-27
    • 2019-04-09
    • 2020-10-15
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    相关资源
    最近更新 更多