【发布时间】:2020-11-03 01:05:41
【问题描述】:
我正在链接 Angular Http 请求,如下所示。问题是当第一个请求失败时,我会在错误回调中得到它,但如果第二个请求失败,则什么也不会发生。
this.myService.requestOne(this.data)
.pipe(mergeMap(dataOne=>{
return this.myService.requestTwo(dataOne);
}))
.subscribe(dataTwo=>{
this.loading = false;
},
(err)=>{
// this fires when only requestOne get failed
this.loading = false;
});
有什么想法吗?
【问题讨论】:
-
因为
requestTwo没有订阅者。 -
那么,应该怎么回答呢?
-
尝试做这样的事情
this.myService.requestTwo(dataOne).pipe(catchError(err => throwError(err))),此时你正在传播错误抛出管道 -
这看起来应该可以工作,我认为问题不在于您的流。你确定 requestTwo 失败了吗?
标签: angular rxjs angular-httpclient