且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular Firebase Firestore获取文档ID

更新时间:2023-02-14 09:24:30

在AngularFirestore中,它只是document.id.但是,要使其正常工作,必须使用snapshotChanges而不是valueChanges.所以:

In AngularFirestore it is simply document.id. But for this to work you must use snapshotChanges instead of valueChanges. So:

orders = this.orderCollection.snapshotChanges();

然后:

<tr *ngFor="let o of orders | async">
    <td>{{o.data().orderName}}</td>
    <td><a (click)="editOrder(o.id)">Edit</a></td>
</tr>

灵感来自: Firestore从集合中获取文档ID 获取包含文档ID的集合.