【问题标题】:Angular Ngfor in json array listjson数组列表中的Angular Ngfor
【发布时间】:2018-09-02 03:02:33
【问题描述】:

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

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);
});

}

表格

在我的桌子上显示我:

[对象对象]、[对象对象]、[对象对象]

我想使用 ngfor 或 [ngForOf] 访问里面的信息

我想用一个来检查我的类别以获取其中的数据, 尝试使用 *ngFor = "let item of categories;" // {{radios.categories.item.description}} 但它不起作用,你能帮帮我吗?

【问题讨论】:

    标签: angular angular-material ngfor


    【解决方案1】:

    也许是这样的?如果您创建了MVCE,那么对您的帮助会容易得多

    <mat-cell  *matCellDef="let radios ">
        <span *ngFor="let category of radios.categories">{{category.description}}</span>
    </mat-cell>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      • 2018-10-09
      • 1970-01-01
      • 2020-12-24
      • 2016-06-12
      • 2018-08-13
      • 1970-01-01
      相关资源
      最近更新 更多