私はAngular 2で簡単な作業をしようとしています。角2 - コンストラクタ呼び出し後のライフサイクルイベント
コンポーネントのコンストラクタの呼び出しが完了した後にイベントを捕捉したいと思います。 私はそうthis-
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import { Profile } from '../../dataModel/Profile.ts'; //Data Model
@Component({
selector: 'profile-list',
template: require('./profileList.component.html'),
styles: [require('./profileList.component.css')]
})
export class ProfileListComponent
{
public profiles: Profile[]; //Can be accessed in view
public loadingMessage: string = "Loading Data ..";
constructor(http: Http)
{
http.get('/api/Profile/Get?currentPageNo=1&pageSize=20').subscribe(result =>
{
this.profiles = result.json();
console.log(result);
});
}
ngOnInit()
{
this.loadingMessage = "No Data Found !!!";
}
}
のようにコンストラクタでのネットワーク呼び出しを作っていますコンストラクタ呼び出しが終了したとき、私はわかりません。
コンストラクタ呼び出しが完了したときにイベントを捕捉したいと思います。
この2 links-
から私は、そうthis-
export class App implements OnInit{
constructor(){
//called first time before the ngOnInit()
}
ngOnInit(){
//called after the constructor and called after the first ngOnChanges()
}
}
を知るようになりました私のconstructor
呼び出しが終了した後にonInit
が呼ばれるのは正しいですか?
私を助けてください。
ご協力いただきありがとうございます。
なぜあなたはコンポーネントフローを制御するための約束ベースの 'getProfile'のようなメソッドを追加できないのですか? constrcutorsとinitalizorsが本質的に非同期ではないと思われる – VadimB
私はロード時にデータを持っていたい –