Reputation: 4987
How to add document id in each of mServiceListObj
this.firestore.collection('service').snapshotChanges().take(1).subscribe(data => {
this.mServiceListObj = data.map(e => {
return {
...e.payload.doc.data()
} as Item;
});
});
In the above code, it is fetching data but without document id.
How to add document id in that object
export class Item {
id: String;
cat: String;
img: String;
title: String;
actiontitle: String;
subt1: String = "milla";
subt2: String;
mServiceIncluded: Array<ServiceIncluded> = [];//=ServiceIncluded();
mServiceDetails: Array<ServiceDetail> = [];//ServiceDetail();
actionlist: Array<ActionModel> = [];
constructor() {
}
setBaseDate(title): Item {
this.title = title;
return this;
}
}
Upvotes: 0
Views: 505
Reputation: 3926
e.payload.doc.id
will give you the id of the document.
So the mapping wil be like this:
return {
...e.payload.doc.data(),
id: e.payload.doc.id
} as Item;
Upvotes: 1