0

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

    }
R. Richards
  • 24,603
  • 10
  • 64
  • 64

1 Answers1

1

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);
    });
}
Amer
  • 6,162
  • 2
  • 8
  • 34