如何获取特定的文档 ID?角火 5.1.1 |云Firestore |文件

How to get the particular document id? AngularFire 5.1.1 | Cloud Firestore | Documents

constructor(private afs: AngularFirestore) {
    this.itemDoc = afs.doc<Item>('items/id');
    this.item = this.itemDoc.valueChanges();
}

现在,this.item 具有除文档的 id 之外的特定文档的值。

我想要id和文档数据。

(或)

如果 snapshotChanges() 是方法,我将如何使用它?

谢谢..!

您无法从 valueChanges 获取文档 ID。顾名思义,它只公开文档的值,而不公开其元数据。

要获取文档ID,您需要观察snapshotChanges instead. Since the snapshotChanges exposes a DocumentChangeAction,您应该可以从this.itemDoc.payload.doc.id获取文档ID。