Having a devil of a time figuring out why this is happening. I've got an A2 project set up using the CLI and I have the following component:
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'app-user-profile-card',
templateUrl: 'user-profile-card.component.html',
styleUrls: ['user-profile-card.component.scss']
})
export class UserProfileCardComponent implements OnInit {
public person;
constructor(private http: Http) {
}
getUserProfile(){
this.http.get('http://somedomain.com/12345')
.map(res => res.json())
.subscribe(
person => { this.person = person.person },
err => console.error(err),
() => console.log(this.person.sex)
);
}
ngOnInit() {
this.getUserProfile();
}
}
The console log for this.person.sex shows the correct value, but when I try to bind to it from the template:
<div>{{ person.sex }}</div>
I get the following error:
undefined is not an object (evaluating 'self.context.person.sex')
Any ideas on this?