【发布时间】:2020-04-22 19:05:51
【问题描述】:
我尝试在 Firestore 中创建一个自动文档 ID,并使用以下代码获取 Angular 8 中的文档 ID,但我在执行完成后获取了文档 ID。有人可以帮助我吗?提前致谢
this.db.collection("testdata2").add({
"name": "Tokyo",
"country": "Japan",
"Date": this.date
})
.then(function(docRef){
component.docid=docRef.id;
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
console.log(component.docid);
【问题讨论】:
-
我不明白你在问什么。到目前为止你写的有什么问题?
-
@DougStevenson 值 component.docid 没有更新任何值,直到我退出函数,但希望它在函数内完成,以便我可以保存文档数组中的id
标签: angular typescript google-cloud-firestore