【问题标题】:How to get a document data angular 6如何获取文档数据角度 6
【发布时间】:2019-04-04 10:02:48
【问题描述】:

我有文档 id 并尝试通过 id 获取文档数据:

export class MyComponent implements OnInit {
  customerDoc: AngularFirestoreDocument<Customer>;
  customer: Observable<Customer>;

    constructor(private afs: AngularFirestore) { 
      const id = this.route.snapshot.paramMap.get('id');  
      this.customerDoc = afs.collection<Customer>('customers/'+id);
      this.customer = this.customerDoc.snapshotChanges();
  }
}

但它什么也没返回。

【问题讨论】:

  • 您检查过您的id 是否为空吗?
  • 是的,身份证是正确的

标签: angular firebase google-cloud-firestore angular6


【解决方案1】:

试试这个,

this.afs.collection<Customer>('customers/'+id).snapshotChanges().map(actions=>{
   return actions.map(b=>{
     const data = b.payload.doc.data();
     const id = b.payload.doc.id;
     return {uid:id,...data}
   })

});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    • 2022-11-07
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    相关资源
    最近更新 更多