Angularfire,snapshotChanges的更改类型始终返回“值”

时间:2019-04-08 06:29:17

标签: angular typescript firebase google-cloud-firestore angularfire2

现在使用Angularfire扩展调用以下代码时:

this.db.doc(path).snapshotChanges();

Angularfire检索DocumentSnapshot,并且无论实际更改类型如何,该类型始终等于“值”,我想知道是否存在变通办法,或者在获取文档时如何在最新版本的Angularfire中实际获取更改类型? ?

我还评论了一年前报告的错误,但我不完全理解成员的评论之一,请点击以下链接:

https://github.com/angular/angularfire2/issues/1762#issuecomment-413929560

谢谢。

2 个答案:

答案 0 :(得分:1)

也许这可以帮助您

this.db
  .collection('collectionName')
  .snapshotChanges()
  .pipe(
    map(snapshots => snapshots.map((action: DocumentChangeAction<any>) => {
      return {
        ...action.payload.doc.data(),
        id: action.payload.doc.id,
        type: action.type
      };
    }))
  );

答案 1 :(得分:0)

根据正式文档,您可以将snapshotChanges()与更改类型一起使用。

this.db.doc(path).snapshotChanges()
  .pipe(map(schedules => console.log(schedules.type)));

enter image description here