使用Angular Fire收听Firestore元数据更改

时间:2018-12-13 05:49:13

标签: firebase google-cloud-firestore angularfire2 progressive-web-apps offlineapps

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

0 个答案:

没有答案