首页 > 解决方案 > 尝试在Angular中的数组中显示表中的数据

问题描述

我在 Angular 6 中有一些代码来显示数据,但是我尝试实现的代码不起作用?到目前为止我的代码:

TS文件

  incident = [ 
    {id: 'E200', product: 'MP2355 Black and white', floor: '2', address: '11 Rue', code: '75019'},
  ];

  incidents = this.incident[0];

HTML 文件

<tr class="" *ngFor="let state of incidents">
    <td>{{state.id}}</td>
</tr>

标签: htmlangular

解决方案


incidents = this.incident[0];

您只从数组中获取一个对象,因此它无法在视图中迭代循环。

this.incidents=this.incident;
<tr *ngFor= "let incident of incidents">
<td>{{ incident.id }} </td>
..
..
</tr>

推荐阅读