This is my code:
import { Component, OnInit } from '@angular/core';
import { AngularFirestore
, AngularFirestoreCollection
, AngularFirestoreDocument } from 'angularfire2/firestore';
import { Observable } from 'rxjs/Observable';
interface Country {
id?: string;
name?: string;
code?: string;
flag?: string;
continent?: string;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'Firestore - Documents';
private countryRef: AngularFirestoreCollection<Country>;
docId: any;
constructor( private afs: AngularFirestore ) {
this.countryRef = this.afs.collection('Country', ref => ref.where('code', '==', 'za'));
this.docId = this.countryRef.snapshotChanges().map( changes => {
return changes.map(a => {
const data = a.payload.doc.data() as Country;
data.id = a.payload.doc.id;
return data.id;
});
});
console.log(this.docId);
}
ngOnInit() {}
}
I am expecting an ugly firestore id but instead I am getting this:
Observable {_isScalar: false, source: Observable, operator: MapOperator}