【发布时间】:2020-03-19 14:01:00
【问题描述】:
我有一个从 Firestore 获取数据的函数:
getLastTime(collectionName: string) {
const docRef = this.afs.firestore.collection(collectionName).doc(this.User).collection('lastTime').doc('lastTime');
docRef.get().then(doc => {
if (doc.exists) {
this.get = doc.data().lastTime;
} else {
this.get = 'Never done';
}
}).catch(error => {
console.log('Error getting document:', error);
});
return this.get;
}
对于我的测试,我实际上在文档“lastTime”中有一个字符串值,它是一个字符串。
在 ngOnInit() 中,我调用了我的函数并 console.log 记录了结果
this.InjuredLastTime = this.getLastTime('INJURY');
console.log(this. this.InjuredLastTime);
通常我应该在控制台中打印我的字符串,但我没有定义......
也许是因为 Firestore 没有足够快地获取我的数据,但我很惊讶,因为 Firestore 正常速度很快......
【问题讨论】:
标签: javascript firebase google-cloud-firestore