所以我在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);
});
}
}
Run Code Online (Sandbox Code Playgroud)
然后在控制台日志中我得到:
无法设置未定义的属性"firstname"
我无法弄清楚.谢谢.