【发布时间】:2019-09-16 14:26:43
【问题描述】:
我在一个页面中有 5 个 api 调用。一些 api 需要 20 秒才能给出响应。有些需要 30 秒才能做出响应。有些需要 10 秒,所以当第一个 api 给出响应时,第一个 api 将加载指示器设置为 false。然后加载指示器消失。但其他 api 仍在工作我想显示加载指示器,直到五个 api 调用响应。你能给我一些想法来完成这项任务吗?
代码:
组件.ts
loading = true;
ngInit() {
this.api1();
this.api2();
this.api3();
this.api4();
this.api5();
}
api1(){
this.loading=true;
this.apiService.api1.subscribe(response => {
loading = false;
}, error=>{
});
}
api2(){
this.loading=true;
this.apiService.api2.subscribe(response => {
loading = false;
}, error=>{
});
}
api3(){
this.loading=true;
this.apiService.api3.subscribe(response => {
loading = false;
}, error=>{
});
}
api4() {
this.loading=true;
this.apiService.api4.subscribe(response => {
loading = false;
}, error=>{
});
}
api5() {
this.loading=true;
this.apiService.api5.subscribe(response => {
loading = false;
}, error=>{
});
}
ApiService.service.ts:
api1(): any {
return this.http.get('apiurl');
}
api2(): any {
return this.http.get('apiurl');
}
api3(): any {
return this.http.get('apiurl');
}
api4(): any {
return this.http.get('apiurl');
}
api5(): any {
return this.http.get('apiurl');
}
【问题讨论】:
-
您可能想查看文档中的操作员决策树应用程序:rxjs-dev.firebaseapp.com/operator-decision-tree
标签: javascript jquery angular css angular7