html - 尝试在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>
解决方案
incidents = this.incident[0];
您只从数组中获取一个对象,因此它无法在视图中迭代循环。
this.incidents=this.incident;
<tr *ngFor= "let incident of incidents">
<td>{{ incident.id }} </td>
..
..
</tr>
推荐阅读
- javascript - 如何避免“框架分离”错误异步验证或使用 Puppeteer 重定向?
- r - 如何增加 R 中基本图的内边距/填充?
- php - 我的 Google Cloud SQL 实例连接和/或查询速度太慢
- python - 如何正确完成 python 3 脚本
- java - 使用片段事务时,片段中未调用 onCreateOptionsMenu。当片段包含在 XML 中时会出现
- python - 我如何知道用户从这个 LabelOptionBox 函数中选择了哪个选项?
- ssh - 尝试使用 eksctl 和 ssh-access 创建 eks 集群
- json - 我想将 json 中的日期和时间格式与 laravel 分开
- javascript - 无效的钩子调用错误:只能在函数组件的主体内部调用钩子
- excel - 取决于组合框值的数据透视表过滤