简体   繁体   English

角度-如何显示对象数组

[英]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.

相关问题 如何在 Angular 4 中显示数组的对象? - How to display objects of an array in Angular 4? 如何使用ngFor Angular 2在对象数组中显示数组 - how to display the array inside an array of objects using ngFor Angular 2 Angular 2如何在对象数组中显示数组对象 - Angular 2 how to display the array object inside an array of objects Angular 2-如何在对象数组中显示数组对象 - Angular 2 - how to display the array object inside an array of objects 如何显示填充有对象 ionic angular 的数组中的数据 - How to display data from an array filled with objects ionic angular 如何使用angular 2在html中显示对象的多嵌套数组 - How to display multi nested array of objects in html using angular 2 如何在Angular 2的html模板中显示对象数组? - How to display an array of objects inside the html template in Angular 2? 如何在 Angular Typescript 中显示数组中的嵌套对象 - How to display nested objects from array in Angular Typescript 如何在 Angular /QuizApp 中显示我的对象数组中的属性 - How to display a property from my array of objects in Angular /QuizApp 如何将Angular中的对象数组转换为字符串数组显示在Angular材质表中? - How to convert an array of objects into array of strings in Angular to display in a Angular material table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM