【问题标题】:How can I iterate through an array in a collection from firestore?如何遍历来自 Firestore 的集合中的数组?
【发布时间】:2019-11-28 23:34:14
【问题描述】:

我在控制台中有一些从 Firestore 返回的数据。我正在尝试循环 cmets 数组。

HTML

  <div style="margin-top: 10px !important;" >   
       <p>{{item.comments[0]}}</p>
  </div>

ts 项目:任何;

 comments: any = [];
 comment: string;


  getData(){
    this.route.data.subscribe(routeData => {
     let data = routeData['data'];
     if (data) {
       this.item = data;
       this.image = this.item.image;  
       console.log(this.item) 
     }
    })   
  }

我在 html 中尝试过 *ngFor="let item of item",但它给了我一个错误提示“错误错误:找不到类型为 'object' 的不同支持对象 '[object Object]'”

【问题讨论】:

  • 如果在 HTML 中使用 *ngFor="let comment of item.comments" 会怎样?

标签: angular typescript ionic-framework angularfire


【解决方案1】:

如果你在 HTML 中使用 *ngFor="let comment of item.comments" 会怎样?

【讨论】:

    【解决方案2】:

    就像错误所说的那样,您实际上是在尝试循环 item。你想要的是在item中循环comments

    <div *ngFor="let comment of item.comments">
        <pre> {{ comment | json }} </pre>
    </div>
    

    【讨论】:

      猜你喜欢
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 2019-02-14
      • 2021-05-28
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      相关资源
      最近更新 更多