AngularFire doesn't detect changes if persistence is enabled

随声附和 提交于 2019-12-24 01:24:56

问题


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

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

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);
});

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.

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

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

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

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

Thx in advance for the help


回答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



来源:https://stackoverflow.com/questions/54664250/angularfire-doesnt-detect-changes-if-persistence-is-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!