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