これがなぜ起こっているのかを判断する悪魔がいます。私は、CLIを使用して設定A2プロジェクトを持っていると私は、次のコンポーネントがあります。角2(TypeScript):HTMLテンプレートのhttp.getからオブジェクトにバインドできません。
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();
}
}
this.person.sexためのコンソールログは、正しい値を示しているが、私はそれからにバインドしようとすると、テンプレート:
<div>{{ person.sex }}</div>
私は次のエラーを取得する:
undefined is not an object (evaluating 'self.context.person.sex')
この上の任意のアイデア?
うわー...このような単純なことだけど巨大な効果。私はあなたの最初の例を使用し、すべてが今素晴らしいです。これは本当にありがとう! – Eric