【发布时间】:2021-02-28 13:23:02
【问题描述】:
我想用嵌套对象填充我的 Person 类 我的 api 响应是:
{
"id": "1001614505887752423",
"type": 1,
"name": "test contact",
"createdAt": "1399/12/10 - 09:51",
"updatedAt": "1399/12/10 - 09:51",
"addresses": [
{
"id": "1001614505887757358",
"personId": "1001614505887752423",
"companyId": null,
"cityId": 66,
"address": "test",
"postalCode": "485484",
"updatedAt": "1399/12/10 - 09:51",
"createdAt": "1399/12/10 - 09:51"
},
{
"id": "100161450588776282",
"personId": "1001614505887752423",
"companyId": null,
"cityId": 45,
"address": "test",
"postalCode": "48548",
"updatedAt": "1399/12/10 - 09:51",
"createdAt": "1399/12/10 - 09:51"
}
]
}
我的 Person 类以对象数组为属性:
export class Person {
id: string;
name: string;
type: number;
addresses: Array<Address>;
createdAt: string;
updatedAt: string;
}
export class Address{
id: string;
address: string;
postalCode: string;
cityId: number;
createdAt: string;
updatedAt: string;
}
所有道具都已填充但 Address[] 未填充, 我这样称呼httpclient:
this.http.get<Person>(url).subscribe(x => this.model = x);
【问题讨论】:
标签: angular typescript observable httpclient