【问题标题】:Execution after .map operator has returned.map 运算符返回后执行
【发布时间】:2018-11-13 11:22:44
【问题描述】:

SomeService.someMethodverifyEmail() 返回一个 observable。

我希望在 map 返回后执行 setTimeout 内的回调

是否可以去掉setTimeout,使用一些RxJs链式方法做一些操作?

SomeService.someMethodverifyEmail()
    .pipe(
      map((data: any) => {
        setTimeout(() => {
          ...
        }, 0);
        return ...;
      }),
      catchError(() => null)
    );

附:请不要问你为什么要这样做的问题!

【问题讨论】:

  • “请不要问你为什么要这样做!”搞笑!
  • 你认为.pipe在做什么?
  • 在地图之后用管子敲击,顺便说一句。

标签: angular rxjs


【解决方案1】:

您可以使用switchMap,更多信息here

SomeService.someMethodverifyEmail()
    .pipe(
      switchMap((data) => {
        // This will fires only when someMethodVerifyEmail() has finish
        return this.someService.someOtherMethod(data)
      }),
      catchError(() => null)
    );

【讨论】:

    猜你喜欢
    • 2019-05-04
    • 2021-08-02
    • 1970-01-01
    • 2012-12-06
    • 2023-01-10
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多