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;
}
}
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.