angular - 在 RXJS Tap 操作符内部时,Console.Log 不会执行

标签 angular typescript rxjs angular10

我有以下观察结果:

this.authenticationService.isSignedIn() -> Observable<Boolean>

this.user$ -> Observable<UserModel>

我需要根据两者检查条件,因此我尝试了:

zip(this.authenticationService.isSignedIn(), this.user$).pipe(
  map(([isSignedIn, user]: [boolean, UserModel]) => isSignedIn && user.claims))
); 

因为我得到了意想不到的结果,所以我尝试使用以下方法检查内容:

zip(this.authenticationService.isSignedIn(), this.user$).pipe(
  tap(([isSignedIn, user]: [boolean, UserModel]) => {
    console.log(isSignedIn);
    console.log(user);
  })
);

但是两个console.log没有执行。我错过了什么?

最佳答案

您可能错过了订阅。所有 rxjs 的东西都是惰性的,在订阅完成之前不会运行。如果除了 tap 运算符之外,您不需要以其他方式处理结果,只需在末尾添加 .subscribe()

zip(...).pipe(
  tap(...)
).subscribe();

关于angular - 在 RXJS Tap 操作符内部时,Console.Log 不会执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63925934/

相关文章:

angular - PrimeNg 条形图如何显示 y 轴的标签

javascript - 带有淡入的 Angular 2 SwitchCase

javascript - Angular 5 - 加载 View 后加载脚本

typescript - 如何编写 PickByValue 类型?

javascript - SwitchMap对自定义主题没有影响?

javascript - Google MAP Places API 不会长时间返回

angular - 名称 'angular' 在当前上下文中不存在 - Angular 2,使用 Material Design CSS

reactjs - 如何更改 NextJS 13 中服务器操作的状态?

rxjs - 分页期间从 springframework.data.repository.reactive.ReactiveCrudRepository 返回 Mono 时出现 "Unsatisfied dependency"异常

javascript - 如何组合 2 个或多个 observables 以便您知道哪个发出了?