angular - Console.Log 在 RXJS Tap 操作符内不执行
问题描述
我有以下可观察的:
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();
推荐阅读
- c# - 旧项目无法识别 lambda 表达式
- mysql - 具有现有值的 Spring Data UPDATE 查询
- machine-learning - 如何在多类文本分类问题中平衡数据?
- r - 在 R 中定义阿拉伯语
- python - 从用户读取输入并使用子进程将其存储到变量中
- c++ - 安装额外模块openCV后未定义跟踪器
- java - (辅助功能)使用 TalkBack 时将自动焦点更改为其他组件
- c# - 如何从 asp.net 应用程序获取所有活动会话
- node.js - 使用 ExcelJS 将多个工作表添加到流工作簿
- windows - Input.GetAxis("Mouse X") 不适用于某些 Windows 配置