Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular forkJoin未等待多个Http请求完成_Angular_Rxjs_Fork Join - Fatal编程技术网

Angular forkJoin未等待多个Http请求完成

Angular forkJoin未等待多个Http请求完成,angular,rxjs,fork-join,Angular,Rxjs,Fork Join,因此,我将向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中

因此,我将向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
    }
)
你能试试下面的方法吗

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
    }
)

forkJoin期望传递的观察值完成——如果它们没有完成——no-go。您能从api请求本身发布更多信息吗?这可能与方法中的
This
范围有关。这不是forkJoin本身的问题。@Rafael我知道。这就是为什么我想在实例中使用forkJoin。我希望在处理subscribe括号下的任何进一步代码之前完成所有三个http调用。奇怪的是,当我单独运行第三个api调用而不是在forkJoin中运行时,它完成得很好。需要注意的一点是,forkJoin中的三个api调用都完成了(我在控制台中看到),这只是出于某种原因,forkJoin本身没有在处理订阅方法调用中的代码之前等待最后一个完成。它一定是错误地完成的,但是我们怎么知道没有看到它的代码!?forkJoin期望传递的观察值完成——如果它们没有完成——no-go。您能从api请求本身发布更多信息吗?这可能与方法中的
This
范围有关。这不是forkJoin本身的问题。@Rafael我知道。这就是为什么我想在实例中使用forkJoin。我希望在处理subscribe括号下的任何进一步代码之前完成所有三个http调用。奇怪的是,当我单独运行第三个api调用而不是在forkJoin中运行时,它完成得很好。需要注意的一点是,forkJoin中的三个api调用都完成了(我在控制台中看到),这只是出于某种原因,forkJoin本身没有在处理订阅方法调用中的代码之前等待最后一个完成。它一定是错误地完成的,但是我们怎么知道没有看到它的代码!?