【发布时间】:2019-09-26 21:17:25
【问题描述】:
所以我在 Angular2 中有这个小应用程序,我正在尝试定义一个对象。这是主要组件。
export class ContactComponent {
person: {
firstname: string;
lastname: string;
}
constructor(private PeopleService: PeopleService){
}
ngOnInit(){
this.PeopleService.fetchData().subscribe(
data=> {
this.person.firstname=data.results[0].name.first;
console.log(this.person.firstname);
});
}
}
然后在控制台日志中我得到:
无法设置未定义的属性“名字”
我想不通。谢谢。
【问题讨论】: