如何获取文档数据角度6

时间:2018-10-31 09:17:21

标签: angular firebase google-cloud-firestore angular6

我有文档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();
  }
}

但是它什么也没返回。

1 个答案:

答案 0 :(得分:0)

尝试一下,

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}
   })

});