小编Ita*_*tay的帖子

在立即更新另一个 Promise 中的值后,在 Promise 中使用 from 运算符时,Observable 会获取错误的值

我有一个observable监听路由变化的:)我还有一个promise可以清除我的本地存储,完成后我立即更改路由,但我的switchMap/switchMapTo内部路由更改可观察到的值得到了旧值..为什么会发生这种情况?

我尝试了很多方法来解决这个问题 - 我发现有两种有效:)但我希望了解它们为什么有效。有人可以帮忙吗?这是关于hot/cold observables问题吗?也许有什么event loop?我真的不知道:)

    this.storageService.clear().then((_) => {
      // this was successful!! And it was checked - user is deleted :)
      // now change the route and trigger the observable below :)
    });
    
    this.router.events.pipe(
      filter((e: Event): e is NavigationEnd => e instanceof NavigationEnd)
      /*
        switchMap in here to get the user!
        Options 1 + 2 show that the user info exists!! 
        Although I know for sure that …
Run Code Online (Sandbox Code Playgroud)

async-await rxjs ionic-framework angular capacitor

5
推荐指数
1
解决办法
657
查看次数

标签 统计

angular ×1

async-await ×1

capacitor ×1

ionic-framework ×1

rxjs ×1