仅收听服务器更新

时间:2019-07-19 23:54:11

标签: javascript firebase google-cloud-firestore angularfire2

如何在AngularFire中实现这一目标?

this.db.collection('users')
      .onSnapshot({ includeDocumentMetadataChanges: true }, function (doc) {
        var result = [];
        doc.docs.forEach(element => {
          if (!element.metadata.hasPendingWrites) {
            result.push(element.data())
          }
        });
        return result;
      });

1 个答案:

答案 0 :(得分:-1)

此代码在AngularFire中应具有相同的作用。

this.angularFirestore.collection('users')
  .snapshotChanges()
  .subscribe(documents => {
    const result = [];

    documents.forEach(document => {
      if (!document.metadata.hasPendingWrites) {
        result.push(document.data());
      }
    });
    return results;
  });