首页 > 解决方案 > 如何将对象数据循环到表中?

问题描述

我有以下带有列和数据的对象。我想使用 *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) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]

标签: angular5

解决方案


您是否尝试过在您的列对象中迭代数据数组?

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

推荐阅读