我的节点 Rest api 有以下输出:
{
"workorder": [
{
"id": 1,
"Workorderno": 110,
"Nfno": 23,
"Amount": 230,
"Orderno": 34,
"createdAt": "2019-03-02 00:19:49.495 +00:00",
"updatedAt": "2019-03-02 12:40:36.647 +00:00"
}
]
}
我想读取输出并使用 Angular 7 将其显示在表格中?有人可以指导我这样做吗?我尝试在我的 REST API 中进行更改,但失败了我可以获得结果
最佳答案
您需要使用 ngFor
进行类似的操作,
<table class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Workorder No</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let work of data.workorder">
<td>{{work?.id}}</td>
<td>{{work?.Workorderno}}</a></td>
</tr>
</tbody>
</table>
</div>
你的界面应该是这样的,
export interface Workorder {
id: number;
Workorderno: number;
Nfno: number;
Amount: number;
Orderno: number;
createdAt: string;
updatedAt: string;
}
然后在你的组件中,
data : Workorder;
constructor(private service: nowService) {
}
ngOnInit() {
this.service.getAll().subscribe((data) => {
this.data = data;
})
}
}
关于javascript - 如何在 Angular 7 中解析 json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54975509/