角度7中的firestore如何获取文档ID

时间:2019-06-08 14:51:24

标签: angular firebase google-cloud-firestore

如何在每个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;
  }
}

1 个答案:

答案 0 :(得分:1)

poor debugability将为您提供文档ID。

所以映射将是这样的:

e.payload.doc.id