5
Angular2で同期してhttpについての例を作成してもらえますか?私は以下のようにしようとしたAngular2 http synchronous
: コンポーネントで:
getAllAddress(){
this.addressService.getAllAddress().then(
result => {
this.data = result.list;
this.onChangeTable(this.config, null);
console.log('FIRST');
}
);
console.log('LAST');
}
サービスで:
public getAllAddress(){
return this.__http.get('LOCATION')
.map((res) => {
return res.json()
})
.toPromise();
}
しかし、コンソールのshow logは '最初の' の前に 'LAST' です。
ありがとうございました。
いいえ、どうぞ、いいえ、しないでください。これは、リクエストが飛行中に文字通りアプリケーションをフリーズするため、ブラウザで実行されているすべてのアプリケーションにとってひどい考えです。これが悪い考えであると言及しているMDNの文書を見てください。 https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest – robwormald