Angular 12 ConcatMap how i can do it?

61 Views Asked by At

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

    }
1

There are 1 best solutions below

0
Amer On BEST ANSWER

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