我一直在加载组件中工作,以便在从 API 调用和加载内容之间进行友好的等待。只是文本时没有问题,但是当信息有图像或更多信息时,加载组件在内容完全加载之前消失。
我查看了 Angular2 的生命周期钩子,但它们中的任何一个看起来都适合我的要求。
主要是我的组件了解 isLoading = true 何时必须消失。
这是我尝试做的方式。
ngOnInit() {
// Payload to call the API
var model: myPayload = {
AuthorId: this._authorid,
CountryId: this._countryid
}
// Api loading
Observable.forkJoin(
this._service.getList(model)
)
.subscribe(
res => {
this.authorList = res[0];
},
null,
() => {
this.isLoading = false
}
)
}