json数组列表中的Angular Ngfor

时间:2018-03-23 12:24:11

标签: angular angular-material ngfor

我尝试捕获我的类别[]的所有内容但我想输入内部的信息,因为有时你有几个列表在里面。这是我的代码

HTML

      <ng-container matColumnDef="category">
        <mat-header-cell *matHeaderCellDef> category </mat-header-cell>
        <mat-cell  *matCellDef="let radios ">
            {{radios.categories}}  --> Get all categorie but not the content inside
        </mat-cell>
      </ng-container> 

组件

  ngOnInit() {
this.componentService.getNewlist()
.then(result => {
    if(!result){
      return;
    }
    this.getresult = result;
    let promises: any[];
    this.getresult.forEach(item=>{
        this.radiosService.getCategid(item.id).then(categories=>{
          promises = categories;
          item['categories']  = promises;
          console.log(promises); <--- GET ALL CONTENT OF MY I get all the information of my category depending on my id
        })

      });
  }) 
    .catch(reason => {
    console.log(reason);
});

}

表格

我表中的

告诉我:

[object Object],[object Object],[object Object]

我想使用ngfor或[ngForOf]

访问内部信息

我想用一个来查看我的类别以获取内部数据, 试试* ngFor =&#34;让类别的项目;&#34; // {{radios.categories.item.description}}但它不起作用,你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

也许是这样的?如果您创建了MVCE

,那么帮助您会容易得多
<mat-cell  *matCellDef="let radios ">
    <span *ngFor="let category of radios.categories">{{category.description}}</span>
</mat-cell>