Я пытаюсь сделать простую работу с 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 Ссылки-
Я узнал this-
export class App implements OnInit{
constructor(){
//called first time before the ngOnInit()
}
ngOnInit(){
//called after the constructor and called after the first ngOnChanges()
}
}
Итак, Правильно ли, что onInit
вызывается после моего звонка constructor
?
Пожалуйста, помогите мне.
Заранее благодарим за помощь.
Почему вы не можете добавить дополнительный метод, такой как getProfile, который основан на обещании для управления потоком вашего компонента? Кажется, constrcutors и initalizors не являются асинхронными по своей природе – VadimB
Я хочу иметь данные во время загрузки –