0

I've seen all the example of using forkJoin with get requests, but all of them use the get directly in the forkJoin. Is it possible to pass in the data service function into the forkJoin? Currently, it is not working for me and I'm just curious if I'm simply missing something.

Here is my current code:

forkJoin([this._dataService.getTradeLetterTotals(this.selectedPlannedBy.PlannedBy_ID, this.selectedProductGroup.Product_Group_ID, 1), 
        this._dataService.getTradeLetterTotals(this.selectedPlannedBy.PlannedBy_ID, this.selectedProductGroup.Product_Group_ID, 2)]).subscribe((results: any) => {
          console.log(results);
          this.tradeLetterFullYearData = results[0].data
          this.tradeLetterAdjPeriodData = results[1].data
          this.isTradeLetterFullYearFinished = true;
          this.checkRemoveLoading();
      });
getTradeLetterTotals(plannedByID, productGroupID, timePeriodID) {
    let cmd = "TradeLetter/Totals/" + plannedByID + "/"  + productGroupID + "/"  + timePeriodID;
    return this.get(this.urlUser() + cmd);
  }
protected get(cmd: string) {
    //console.log(cmd)
    return this._http.get(cmd);
  }

So in my component, I'm passing in parameters to the data service to build the get request and make the call. Normally, in the component, I would just subscribe to that call and get the data back and do whatever with it. But I want to try and be a little more efficient in my code since I'm simply changing one parameter and calling the same function again. I know I could do a pipe and mergeMap but it didn't seem like I could access the first return using that method. Any suggestions/ideas?

4
  • learnrxjs.io/learn-rxjs/operators/combination/forkjoin Commented Nov 24, 2022 at 3:47
  • stackblitz.com/edit/… Commented Nov 24, 2022 at 3:53
  • So is it that I have to use interfaces for it to work? I'm not seeing any glaring differences in what I'm doing and your example? Commented Nov 25, 2022 at 13:29
  • I took your example and put it into my app, and it has the same issue with not returning. So now I have no idea what's wrong Commented Nov 25, 2022 at 14:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.