我有文档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();
}
}
但是它什么也没返回。
答案 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}
})
});