私のコードで何が間違っているのかわかりません。私は角度コードから残りのAPIを呼び出そうとしていますが、 "定義されていないプロパティ 'id'を読み取ることができません。コンポーネントでangular2から残りのAPIを呼び出すと、定義されていません。
私のコードは次のようになります。コンソールでエンドとバックエンドで
ngOnInit(): void{
this.getWod();
}
getWod(): void {
let id;
this.route.params.forEach((params: Params) => {
id = +params['id'];
})
this.wodService.getWod(id).then(wod => this.wod = wod);
console.log(this.wod);
}
、私はバックエンドが正しく呼び出されていることがわかります。コンソールでのネットワークタブを読み込む:コンポーネントのcorrospondingのHTMLページに
wod: {id: 16, name: "test name", description: "test description", wod_type_id: 3, wod_category_id: 3}
私は単に持っている:
<div>{{wod.id}}</div>
「未定義」の結果の上にconsole.log方法、I単にdosenどうして? UPDATED
:
getWod(id: number): Promise<Wod>{
const url = `${this.getWodUrl}/${id}`;
return this.http.get(url)
.toPromise()
.then(response => response.json().wod as Wod)
.catch(this.handleError);
}
Ayのアイデア:
マイgetWodの流通サービスコードは次のようになりますか?
あなたのコンポーネントに 'wod'と宣言している部分を私たちに示すのを忘れました。問題はおそらくそこにあります。 – lexith