如何获得 Observable.forkJoin 的全部结果

How to get the whole result of Observable.forkJoin

我想调用几个http调用,得到所有响应后再做一些操作。

我尝试使用 Observable.forkJoin,它工作正常,直到某些调用出错。似乎它将捕获第一个响应错误以进行错误处理并丢失其他错误。我想要所有请求的完整列表,状态为成功或失败。

const requests: Observable<any>[] = [];
requests.push(...);
requests.push(...);
requests.push(...);

Observable.forkJoin(requests).subscribe(response => {
  ...
}, error => {
  ...
});

您可以在每个请求上添加 catchError 运算符

requests.push(...pipe(
  catchError(val => console.log(val))
));

您可以在每个请求中使用 .pipe 运算符,同时将其推送到数组

request.pipe(
    catcherror (this.handleerror);
    )

    function handleerror (err){

    }