【发布时间】:2020-09-22 02:08:28
【问题描述】:
我正在尝试使用 get 请求让嵌套对象显示在模板中。问题是它显示了我的对象的主要属性,不过是嵌套对象。
export class User {
userId: number;
userName: string;
password: string;
firstName: string;
lastName: string;
role: number;
inforamation: Information;
}
这是我的模型,它可以显示用户属性但不能显示信息。
getAllUsers(){
const header = new HttpHeaders({
'Content-Type': 'application/json'
});
return this.usersapiservice.getData(this.REST_API_SERVER, {headers : header});
}
ngOnInit(){
this.getAllUsers().subscribe((data: User[]) => {
this.users = data;
});
}
在我的html中
{{users.firstname}} // work
{{users.information.adress}} // Does not work`
【问题讨论】:
-
你能在
this.users = data;行之后做console.log(this.users),请检查对象在控制台中的样子
标签: angular api httpclient