如果启用持久性,AngularFire 不会检测更改 [英] AngularFire doesn't detect changes if persistence is enabled

查看:22
本文介绍了如果启用持久性,AngularFire 不会检测更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AngularFire 并且在我的 应用程序中启用了离线支持的持久性.module.ts:

I'm using AngularFire and have the persistence for offline support enabled in my app.module.ts:

imports: [
   AngularFireModule.initializeApp(environment.firebase),
   AngularFirestoreModule.enablePersistence()
]

当我的应用程序启动时,我使用 valueChanges() 检索用户,如下所示:

When my application start, I retrieve the user using valueChanges() like the following:

const doc: AngularFirestoreDocument<User> = this.myCollection.doc<User>(userId);

doc.valueChanges().pipe(take(1)).subscribe((user: User) => {
    console.log(user);
}, (err) => {
    console.err(err);
});

令我感到奇怪的是,如果我将修改作为应用程序从另一个来源应用到数据库,例如,如果我将自己登录到 Google Firestore 控制台并手动修改用户数据中的值,则不会获取这些数据.

Strangely to me, if I applies modifications to the database from another source as the application, for example if I log my self into the Google Firestore Console and modify manually a value in the user data, these data won't be fetched.

如果我重新启动应用程序,它将始终获取本地持久化数据,并且永远不会注意到值已更改.

If I restart the app it will always fetch the locally persisted data and will never notice that the values were changed.

如果我删除持久性,分别是enablePersistence(),数据将被正确获取.

If I remove the persistence, respectively the enablePersistence(), the data are correctly fetched.

你知道问题的原因是什么吗?

Do you know what's the reason of the problem?

在这种情况下,我不应该使用 valueChanges() 吗?

Should I not use the valueChanges() in such case?

还是因为我只获取了一次值(请参阅take(1)),因此从未获取更新的值?

Or does this happens because I fetch the value only once (see take(1)) and therefore the updated value is never fetched?

提前感谢帮助

推荐答案

5 分钟后...正是我的问题是我没有监听更改而只读取一个值 (take(1)),分别读取本地持久化的,之后不会再读取,因此不会获取更新的值

5 minutes later...exactly my problem is the fact that I'm not listening for changes and only reading one value (take(1)), respectively the locally persisted one will be read and nothing more afterwards, therefore the updated value won't be fetched

这篇关于如果启用持久性,AngularFire 不会检测更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆