this.F1().subscribe(result => {
this.F2(result);
})
F1() {
return this.graphDataService.getAvailableSpan(a, b).subscribe(res => {
this.c = new Date(res.lastAvailableDate);
return 1;
}, error => {
this.lastAvailableDate = new Date();
return 1;
})
}
答案 0 :(得分:0)
检查此 How can I call multiple API's on a function with Angular?
async apicall(){
let data1 = await f1(); //your first function should return promises
let data2 = await f2(); //your second function should return promises
}
答案 1 :(得分:0)
您可以这样做:
async getAsyncCall() {
this.result = await this.httpclient.get(this.URL).toPromise();
this.F2(result);
}
答案 2 :(得分:0)
您可以使用RxJS运算符使流异步。尝试以下
ngOnInit() {
this.F1().subscribe(result => {
this.F2(result);
});
}
F1(): Observable<any> {
return this.graphDataService.getAvailableSpan(a, b).pipe(
tap((res) => {
this.c = new Date(res.lastAvailableDate);
}),
catchError((error) => { // <-- `catchError` should return an obervable
this.lastAvailableDate = new Date();
return of(error);
})
);
}