Can't get $key from firebase on angular 2
on service.ts `import { Injectable } from '@angular/core'; import { AngularFirestore,AngularFirestoreCollection } from "angularfire2/firestore"; import { Observable } from "rxjs/Observable"; import {Business} from "../Business"; import { Category } from "../Category";
@Injectable() export class FirebaseService{
//collection
private _businessCollection : AngularFirestoreCollection<Business>;
private _categoryCollection : AngularFirestoreCollection<Category>;
businesses: Observable<Business[]>;
categories: Observable<Category[]>;
constructor(private _af:AngularFirestore)
{
this._businessCollection = _af.collection<Business>('businesses');
this._categoryCollection = _af.collection<Category>('categories');
}
getBusinesses(){
this.businesses = this._businessCollection.valueChanges();
return this.businesses;
}
getCategories(){
this.categories = this._categoryCollection.valueChanges();
return this.categories;
}
} `
on ngOnInit ` businesses: Business[];
//Get data of business this._firebaseService.getBusinesses().subscribe(data=> { this.businesses = data; }); //Get data of category this._firebaseService.getCategories().subscribe(data=> { this.categories = data; }); }`
on html, I called it by *ngFor
but it is null or underfine.

You are using Firestore, no Realtime Database. There is no $key in Firestore.
You have to use snapshotChanges() in order to retrieve the id of the document: https://github.com/angular/angularfire2/blob/master/docs/firestore/collections.md#snapshotchanges
https://stackoverflow.com/a/51459727/7204574