根据https://firebase.google.com/docs/firestore/query-data/listen处的Firebase文档,可以将{includeMetadataChanges:true}添加为.onSnapshot()方法的选项。如何使用angular / fire / firestore做到这一点,以便我的应用程序可以知道何时将数据以脱机状态的PWA发送到服务器上?到目前为止,这是我目前无法使用的内容:
this.afs.collection(`collection`).snapshotChanges({includeMetadataChanges: true}).pipe(
map(arr => {
return arr.map(snap => {
const id = snap.payload.doc.id;
const data = snap.payload.doc.data() as Entry;
const fromCache = snap.payload.doc.metadata.fromCache;
const hasPendingWrites = snap.payload.doc.metadata.hasPendingWrites;
return { fromCache, hasPendingWrites, id, ...data };
});
})
)