So I have this little app in Angular2, and I'm trying to define an object. This is the main component.
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);
});
}
}
Then in the console log I get:
Cannot set property 'firstname' of undefined
I can't figure it out. Thanks.