![](/img/trans.png)
[英]How to manipulate the key of array of object into ngfor in angular 8
[英]object-key value array in *ngFor for angular 7
我需要在表格中設置 object 數組值,但結果沒有反映。
<ng-container *ngFor="let file of err_data ">
<tr>
<td>{{file.details.commodity_name}}</td>
<td>{{file.row}}</td>
<td *ngFor="let error of file.errors | keyvalue">
<div *ngFor="let error_type of error[key] | keyvalue">
{{ error_type}}
</div>
</td>
</tr>
</ng-container>
你不需要 <div *ngFor="let error_type of error[key] | keyvalue">
看看下面的代碼
<ng-container *ngFor="let file of err_data ">
<tr>
<td>{{file.details.commodity_name}}</td>
<td>{{file.row}}</td>
<td *ngFor="let error of file.errors | keyvalue">
{{error.key}} --- {{error.value[0]}}
</td>
</tr>
</ng-container>
Your key value is undefined, your file.errors is an object which can't be iterated through *ngFor.
如果 object 格式始終是標准格式,您可以這樣做
<td *ngFor="let error of file.errors | keyvalue">
<div *ngFor="let error_type of error | keyvalue">
{{ error_type.tax}} {{error_type.unit}}
</div>
</td>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.