3
我想要一個替代角1中的$ http.pendingRequest或任何東西跟蹤全局像攔截器。主要用於展示,而調用已取得如何跟蹤角2中的掛起的HTTP請求
我想要一個替代角1中的$ http.pendingRequest或任何東西跟蹤全局像攔截器。主要用於展示,而調用已取得如何跟蹤角2中的掛起的HTTP請求
加載圖標你可以做這樣的事情:
getItem(itemID:string){
if(this.pendingRequest){
this.pendingRequest.unsubscribe();
}
this.pendingRequest = this.http.get(`./country-info/${itemID}`).map((res: Response) => res.json()).subscribe(res => this.item = res.item);
}
我可能只是維持圖標的狀態,而觀察到的至今未歸。
實施例:
export class MyClass {
private isLoaded = false;
constructor(private myService: MyService){}
ngOnInit(){
this.myService.myServiceCall().subscribe(data => {
console.log(data);
this.isLoaded = true;
});
}
}
然後對話框上使用*ngIf
。您還可以考慮使用Angular爲這種場景提供的異步管道:
https://angular.io/docs/ts/latest/api/common/index/AsyncPipe-pipe.html