0

我想连接 tow api 调用。我如何在此代码上使用 ConcatMap ?

    getHIndices(code) {

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

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

    }
4

1 回答 1

2

尝试以下操作:

getHIndices(code) {
  this.api
    .getInstrumentHistoryIndices(code, '3M')
    .pipe(
      tap(response1 => {
        this.prepareDataForHistory(response1);
      }),
      concatMap(() => this.api.getInstrumentHistoryIndices(code, '5Y'))
    )
    .subscribe(response2 => {
      this.prepareDataForHistory2(response2);
    });
}
于 2021-09-01T12:12:33.007 回答