【问题标题】:Angular 12 ConcatMap how i can do it?Angular 12 ConcatMap 我该怎么做?
【发布时间】:2021-09-01 11:59:07
【问题描述】:

我想连接 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);

    }

【问题讨论】:

    标签: angular rxjs httpclient concatmap


    【解决方案1】:

    尝试以下方法:

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

    【讨论】:

      猜你喜欢
      • 2017-08-26
      • 2018-01-16
      • 2012-05-26
      • 1970-01-01
      • 2014-01-23
      • 2011-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多