嵌套的HTTP调用不适用于ForkJoin

时间:2019-07-25 14:32:05

标签: angular rxjs angular6 observable

我有一个父HTTP请求,需要首先完成它(getTrialForPatient),响应时,我需要再执行两个需要并发的http请求(getDailyQuestionaireData,getStartEndQuestionaireData) 我尝试使用forkJoin,但无法成功。知道我做错了什么吗?

private _trialListPoll$ = timer(0, this.listRequestInterval).pipe(switchMap(()=>{
    return this.trialDataService.getTrailForPatient(this.patientId).pipe(map(data=>{
      if(data && data.result && data.result.length > 0){
        const trial = data.result[0] as TrialPhase;
        this.trialId = trial.trialId;

      return data.result[0];
    }));
    }
  ),switchMap(()=>forkJoin( this.trialDataService.getDailyQuestionaireData(this.trialId),this.trialDataService.getStartEndQuestionaireData(this.trialId)),tap(([res1, res2])=> {
    console.log(res1,res2,"works ? ")
    }))

    ,share());

0 个答案:

没有答案