Za pomocą metody snapshotChanges() chcę pobrać id obiektu z bazy.
service.ts
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
import { IGallery } from '../interfaces/igallery';
import { timestamp } from 'rxjs/operator/timestamp';
@Injectable()
export class GalleriesService {
GalleriesCol: AngularFirestoreCollection<IGallery>;
galleriesObservable: Observable<any[]>;
...................
constructor(private db: AngularFirestore) {
db.firestore.settings({ timestampsInSnapshots: true });
this.galleriesObservable = this.db.collection('galleries').snapshotChanges().map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as IGallery;
data.galleryId = a.payload.doc.id;
console.log(data);
return data;
});
});
}
getGalleries() {
return this.galleriesObservable;
}
...................
}
Metoda w app.component.ts, która ma pobierać dane z serwisu
getGalleries() {
this.galleriesService.getGalleries()
.subscribe(
data => {
........................................
}
);
}
W konsoli dostaję taki błąd.
Szukałem rozwiązania praktycznie wszedzie ale nie wiele można znaleźć na temat tego błędu.
package.json :
https://pastebin.com/rktki8QL
Edit.
Kiedy zamiast snapshotChanges() uzywałem valueChanges() to wszystkie obiekty pobierały się bez problemu.
getGalleries() {
this.GalleriesCol = this.db.collection('galleries');
return this.GalleriesCol.valueChanges();
}
struktura "bazy" :