Reputation: 1885
right now when calling the following code using the Angularfire extension:
this.db.doc(path).snapshotChanges();
Angularfire retrieves a DocumentSnapshot and a type that is always equal to "value" regardless of the real change type, I wonder if there's a workaround or how can I actually get the change type in the latest version of Angularfire when fetching a document?
I also commented on a bug reported like a year ago but I don't fully understand one of the comments made by a member, please follow this link:
https://github.com/angular/angularfire2/issues/1762#issuecomment-413929560
Thanks in advance.
Upvotes: 0
Views: 963
Reputation: 1384
base on the official document, you can use the snapshotChanges()
with change type.
this.db.doc(path).snapshotChanges()
.pipe(map(schedules => console.log(schedules.type)));
Upvotes: 0
Reputation: 350
Maybe this can help you
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
};
}))
);
Upvotes: 1