angular 使用observable同时发送多个Http 请求
场景
- 用户有多个api 同时请求时,使用observable 一次发送多个http 请求。
// 倒入rxjs
import { forkJoin } from 'rxjs';
const observable = forkJoin([
this.monitorLoadDataService.doGetIndices(),
this.monitorLoadDataService.doGetIndexMapping(this.DEFAULT_INDICES),
...
]);
observable.subscribe({
next: (results: any) => {
// result0
if (results[0].status === 200) {
} else {
}
// result1
if (results[1].status === 200) {
} else {
}
},
error: () => {},
complete: () => {
this.isSpinning = false;
this.discover();
}
},);