获得承诺价值后返回可观察性

问题描述 投票:-1回答:1

我有以下代码,但它不起作用,我希望一旦承诺得到解决就返回一个observable。有任何想法吗?任何建议都是受欢迎的

  getParalelos() {

    let _observable;
    this.getToken().subscribe(token => {
      _observable = this.http.get(`${this.url}/paralelo?token=${this.token}`, httpOptions)
    })
    return _observable;
  }
angular typescript web
1个回答
2
投票

您可以使用flatMap。

http://reactivex.io/documentation/operators/flatmap.html

import { flatMap } from "rxjs/operators";

getParalelos() {
    return this.getToken().pipe(
        flatMap(token => {
            return this.http.get(`${this.url}/paralelo?token=${this.token}`, httpOptions)
        })
    );
}
© www.soinside.com 2019 - 2024. All rights reserved.