[英]Angular - How to display array of objects
I have a basic Firestore collection query. 我有一个基本的Firestore集合查询。 I've added each of the returned items into an array of objects. 我已将每个返回的项目添加到对象数组中。 What I'd really like to do is loop over these in the HTML and display the key and value. 我真正想做的是在HTML中循环这些并显示键和值。
firestore_albums = [];
...
getData() {
this.db.collection(`users/myid/albums`).get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
const data = doc.data();
this.firestore_albums.push({ ...data });
});
})
HTML HTML
<div *ngFor="let item of firestore_albums | keyvalue">
{{item.key}}:{{item.value}}
</div>
Unfortunately, this just returns: 不幸的是,这只是返回:
0:[object Object] 0:[对象对象]
1:[object Object] 1:[对象对象]
This seemed to work! 这似乎有效!
<ul>
<li *ngFor="let item of firestore_albums">
<ul>
<li *ngFor="let key of item | keyvalue">
<div>{{key.key}}</div>
<div>{{key.value}}</div>
</li>
</ul>
</li>
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.