AngularFire doesn't detect changes if persiste

2019-07-15 12:15发布

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条回答
时光不老,我们不散
2楼-- · 2019-07-15 12:34

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

查看更多
登录 后发表回答