【发布时间】:2020-11-17 10:18:29
【问题描述】:
(抱歉英语不好,我不是母语人士)
我在将值传递给对象并在 html 中显示它时遇到问题。
以下是我的代码:
completeUserProfile = {};
async testfunction() {
const sampleArray = [1, 2];
const interestRef = this.firestore.firestore.collection('interest');
const result = interestRef.where('interestIn', 'array-contains-any', sampleArray).get();
await result.then(querySnapshot => {
querySnapshot.forEach(doc => {
this.completeUserProfile[doc.data()['uid']] = {};
this.completeUserProfile[doc.data()['uid']].uid = doc.data().uid;
this.completeUserProfile[doc.data()['uid']].interestIn = doc.data().interestIn;
this.completeUserProfile[doc.data()['uid']].updatedAt = doc.data().updatedAt.toDate();
this.firestore.firestore.collection('userInformation').where('uid', '==', doc.data().uid).limit(1)
.get().then((userInfo) => {
userInfo.forEach(doc => {
this.completeUserProfile[doc.data()['uid']].realName = doc.data().realName;
})
})
console.log(this.completeUserProfile[doc.data()['uid']]);
})
});
}
我可以在console.log 中毫无问题地看到结果。但是,我无法使用 ngFor 循环在 html 中显示我的信息。即使我只是{{completeUserProfile }},我也会得到[object Object]的结果。
在过去一个月处理 Angular 时,我意识到我必须使用 : 而不是 = 来声明对象(在本例中为 completeUserProfile)。但在这种情况下,我没有这样做。我需要帮助。感谢您抽出宝贵时间阅读本文。
【问题讨论】:
-
您正在尝试迭代 Json 属性
-
我是新手,我不确定您所指的 Json 属性是什么。如果您能更准确地告诉我我应该做什么,我将不胜感激。谢谢
标签: angular typescript firebase google-cloud-firestore