[英]firestore in angular 7 how to get document id
如何在每個mServiceListObj中添加文檔ID
this.firestore.collection('service').snapshotChanges().take(1).subscribe(data => {
this.mServiceListObj = data.map(e => {
return {
...e.payload.doc.data()
} as Item;
});
});
在上面的代碼中,它正在獲取數據但沒有文檔ID。
如何在該對象中添加文檔ID
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
將為您提供文件ID。
因此映射將如下所示:
return {
...e.payload.doc.data(),
id: e.payload.doc.id
} as Item;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.