【发布时间】:2020-03-10 12:14:37
【问题描述】:
我有一个看起来像这样的 Firestore 数据库。 我目前正在从 userFavorites 集合中检索数据。
我最喜欢的服务
async getfavoriteList(): Promise<firebase.firestore.QuerySnapshot> {
const user: firebase.User = await this.authService.getUser();
if (user)
{
this.FavoriteListRef = firebase
.firestore()
.collection(`userFavorites`);
return this.FavoriteListRef.where('uid', '==', user.uid).get();
}
}
}
最喜欢的TS
favoriteList: any;
public favoriteListRef: firebase.firestore.CollectionReference;
this.favoriteService.getfavoriteList().then(favoriteListSnapshot => {
this.favoriteList = [];
favoriteListSnapshot.forEach(snap => {
this.favoriteList.push({
id: snap.id,
favoriteList: snap.data().favourite
});
console.log(snap.data().favourite)
return false;
});
});
}
现在,当我使用 --console.log(snap.data().favourite) 控制台记录这些数据时,
我在控制台中看到了数据。
但是,我尝试过的以下 HTML 未在视图中显示此数据。 我也尝试过使用 JSON 管道转储数据。
<ion-grid>
<ion-row>
<ion-col size="12" >
<ion-card *ngFor ="let favorite of favoriteList">
<!-- <img [src]="favorite?.image[0]">
<img [src]="favorite?.favorite.image[0]"> -->
<div class="card-title">{{ favorite | json }}</div>
<div>{{favorite?.description}}</div>
</ion-card>
</ion-col>
</ion-row>
</ion-grid>
我做错了什么?
【问题讨论】:
-
控制台有错误吗?
-
糟糕的问题命名:)
-
favoriteList 可能为空
-
你可以尝试用
JSON.stringify()显示它
标签: angular typescript google-cloud-firestore ionic4