我想用从传入的对象与角数据动态填充一个HTML表格。
只要我尝试在我的对象的“第一级”访问值,代码工作正常。 问题是,我不能从嵌套对象访问值。 任何人有一种变通方法?
table.component.ts:
setTable(headers: string[],attributes: string[], obj: any) {
this.obj = obj;
this.tableHeaders = headers;
this.attributes = attributes;
}
table.component.html:
<td *ngFor="let header of tableHeaders; let i = index" >{{ object[attributes[i]]}}</td>
父组件:
this.table.setTable(
['First Name', 'Phone', 'City'],
['name', 'phone', '??????'], // Where ???? I have tried both address.street and address[street] and nothing is displayed, and when I try address [object Object] is displayed.
aUserObject
);
user.model.ts:
export class User {
id: number;
name: string;
phone: string;
email: string;
address: Address;
}
所在地址也是一个对象,有一个属性street
。