如何获取特定的文档ID? AngularFire 5.1.1 | Cloud Firestore |文件资料

时间:2019-01-07 02:58:55

标签: angular google-cloud-firestore angularfire5

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

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

我需要id和文档数据。

(或)

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

谢谢..!

1 个答案:

答案 0 :(得分:2)

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

要获取文档ID,您需要观察snapshotChanges。由于snapshotChanges公开了DocumentChangeAction,因此您应该能够从this.itemDoc.payload.doc.id获取文档ID。

相关问题