Ultranuke
Ultranuke

Reputation: 1885

Angularfire, change type from snapshotChanges always returns "value"

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

Answers (2)

youDaily
youDaily

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)));

enter image description here

Upvotes: 0

Wojciech Parys
Wojciech Parys

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

Related Questions