forkJoin 不等待多个 Http 请求完成

forkJoin not waiting for multiple Http requests to finish

所以我有三个要传递给 forkJoin 的 http 请求:

apiRequest1 = this.http.getApi1('...');
// The same format is for the remaining api requests.

forkJoin(apiRequest1, apiRequest2, apiRequest3)
    .subscribe(([results1, results2, results3]) => { rest of code }

results3 中的数据不断返回为空数组。如果我 运行 HttpRequest 本身并订阅它,数据返回就好了。有什么办法可以解决这个问题吗?

你能试试下面的方法吗:

forkJoin(
  apiRequest1, apiRequest2, apiRequest3
).subscribe(
    response =>{
      //response[0] is data returned by API apiRequest1
      //response[1] is data returned by API apiRequest2
      //response[2] is data returned by API apiRequest3
    }
    error => console.log("Error: ", error),
    () =>{
      //All the API calls are completed here. Put your code here
      //codes should be executed after the completion of all API calls
    }
)