代码之家  ›  专栏  ›  技术社区  ›  Govind Samrow

如何获取文档数据角度6

  •  0
  • Govind Samrow  · 技术社区  · 7 年前

    我有文档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 回复  |  直到 7 年前
        1
  •  0
  •   Parth Lukhi    7 年前

    试试这个,

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

    推荐文章