【发布时间】:2017-06-13 10:51:07
【问题描述】:
我正在尝试从响应中读取数据并将其设置在我的 HTML 中。但它给了我未定义的错误。谁能帮助我在这里做错了什么。
以下是组件的sn-p:
userProfile: any
constructor(private _userProfileService: UserProfileService ){}
ngOnInit(){
this._userProfileService.getProfileData()
.subscribe(data => {
console.log("Response");
console.log(data);
this.userProfile = data;
console.log(this.userProfile.user.firstname);
});
}
HTML:
<h2>{{userProfile.user.firstname}} {{userProfile.user.lastname}}'s Profile <a href="#"><img src="assets/img/pen.png" alt="pen"></a></h2>
【问题讨论】:
-
修复了这一行:userProfile: any = {};
-
只有一个问题,你为什么不接受我的回答,因为它是第一个?
-
@VivekDoshi 首先感谢您的回答,它解决了我的问题。我没有检查谁在几毫秒发布了答案,据我了解,这个社区是为了帮助开发人员解决不为小事争吵。
标签: angular