Reputation: 1
I'm trying to get my firebase data node keys using AngularFireList
Data.ts
getAddress(user){
this.AngularFireDatabase.list(`Profiles/Users/${user.uid}/address`);}
SendingData.ts
this.data.getAddress(user).valueChanges().subscribe(item=>{})
I'm getting everything that I have in child nodes, how can I get the key ? for example in the image I have Address/Home/ and in-home I have a name , lat, lng. here I want to get Home which is the key of these child nodes.
Firebase Data Image:
Any Solution?
Upvotes: 0
Views: 1388
Reputation: 41
If you want to get the key you must use snapshotChanges() instead of valueChanges() , read Angularfire2 docs.
This is one of my codes look at it , in the TS file :
ParkingSpotList$: Observable<any[]>; // write this as global variable before constructor
this.ParkingSpotList$ = this.AFD.ShowParkingSpot().snapshotChanges().map(changes => {
console.log(changes)
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }))
});
then in HTML (i get the key by writing "PS.key") :
<ion-list>
<ion-item *ngFor="let PS of ParkingSpotList$ | async" (click)="ReserveParkingSpot(PS.key)">
{{PS.PlateNo}}
</ion-item>
</ion-list>
Upvotes: 4