如何将对象数据循环到表中?

时间:2018-12-11 04:30:14

标签: angular5

我有以下带有列和数据的对象。我想使用* ngFor显示列值。

到目前为止,我已经尝试了以下代码:

public productLists;

this.productLists = [];
this.productLists = this.loadProductLists();

html

<tr *ngFor="let column of productLists.columns">
                    <th scope="col">{{column}}</th>
                </tr>

数据

columns:
action: "Action"
product_code_clip: "Product Code Clip"
product_name_clip: "Product Name Clip"
year: "Year"
__proto__: Object
data: (15) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]

1 个答案:

答案 0 :(得分:0)

您是否尝试过对专栏对象中的数据数组进行迭代?

<tr *ngFor="let column of productLists.columns.data">
                    <th scope="col">{{column}}</th>
                </tr>