我希望使用Angular传入的对象中的数据动态填充HTML表。
只要我尝试访问对象的“第一级”上的值,代码就可以正常工作。问题是我无法从嵌套对象访问值。有人有解决方法吗?
table.component.ts:
class ReportMyConversationTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function shouldInit()
{
//given
//when
//then
}
/**
* @test
*/
public function shouldIndex()
{
//given
//when
//then
}
/**
* @test
*/
public function shouldSearch()
{
//given
//when
//then
}
/**
* @test
*/
public function shouldDoSomethingImportant()
{
//given
//when
//then
}
}
table.component.html:
setTable(headers: string[],attributes: string[], obj: any) {
this.obj = obj;
this.tableHeaders = headers;
this.attributes = attributes;
}
父组件:
<td *ngFor="let header of tableHeaders; let i = index" >{{ object[attributes[i]]}}</td>
user.model.ts:
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
);
Where Address也是一个对象,具有属性export class User {
id: number;
name: string;
phone: string;
email: string;
address: Address;
}
。