zakaria1153
zakaria1153

Reputation: 11

Angular 12 ConcatMap how i can do it?

I want to concat the tow api call. How i can use ConcatMap on this code ?

    getHIndices(code) {

        
        this.api.getInstrumentHistoryIndices(code, '3M')
            .subscribe((response: {}) => {
                this.prepareDataForHistory(response);
            });

        setTimeout(() => {
            this.api.getInstrumentHistoryIndices(code, '5Y')
            .subscribe((response: {}) => {
                this.prepareDataForHistory2(response);
            });
        }, 300);

    }

Upvotes: 0

Views: 69

Answers (1)

Amer
Amer

Reputation: 6706

Try the following:

getHIndices(code) {
  this.api
    .getInstrumentHistoryIndices(code, '3M')
    .pipe(
      tap(response1 => {
        this.prepareDataForHistory(response1);
      }),
      concatMap(() => this.api.getInstrumentHistoryIndices(code, '5Y'))
    )
    .subscribe(response2 => {
      this.prepareDataForHistory2(response2);
    });
}

Upvotes: 1

Related Questions