我如何做Angular ngFor迭代

时间:2018-10-22 12:21:12

标签: javascript angular

有人可以帮助我如何在模板中填充以下json数据。这是我的代码:

app.html

<div *ngFor="let item of dataSource">
  Key: <b>{{item.referenceID}}</b> and Value: <b>{{item.merchantID}}</b>
</div>

app.ts

dataSource: MatTableDataSource<MerchantFinanceElement>;

this.abstractRestService.get('finance').subscribe(
  (response: any) => {
    const merchantFinanceData: MerchantFinanceElement[] = response;
    this.dataSource = new MatTableDataSource(merchantFinanceData);
    this.dataSource.sort = this.sort;
    this.dataSource.paginator = this.paginator;
    console.log('this.dataSource', this.dataSource.data);
  },
  (error: any) => {
    console.log(error);
  }
);

enter image description here

1 个答案:

答案 0 :(得分:0)

只需添加filtredData

<div *ngFor="let item of dataSource.filtredData |async">
  Key: <b>{{item.referenceID}}</b> and Value: <b>{{item.merchantID}}</b>
</div>