angular - RXJS - Angular : Two Observable should return Observable
问题描述
I want to evaluate two observable<boolean>
and I would like to save the flow in another observable<boolean>
.
I tried combineLatest(obs1$, obs2$);
but it generates an observable<[boolean, boolean]>
.
Is there a better function than combineLatest
to evaluate both observables and returns another observable<boolean>
?
解决方案
如果要将结果合并到单个流中,请使用merge() from 'rxjs'
. 如果要对两者执行逻辑操作:
结合最新接受的项目函数作为最后一个参数,例如
combineLatest(obs1$, obs2$, ([first, second]) => first || second) ;
它已被弃用。所以你需要使用map
.
combineLatest(obs1$, obs2$,).pipe(
map([first, second]) => first || second)
);
推荐阅读
- mysql - MySQl/Laravel:在更新记录之前检查更改的列
- mpi - 如何检测 MPI_Request 对象是否由 MPI_Isend 或 MPI_Send_init 启用?
- javascript - 将 v-model 作为数组传递给组件时 Vue js 出现问题?
- sql - PostgreSQL:使用 join 和 group by 查询花费的时间太长
- javascript - 如何检测元素是否有 ::after(伪元素)?
- r - 无法转换包含数据框的列表
- java - 即使没有注释,Junit 5 在 Maven 构建中执行测试
- angular - 角垫桌
- python - 使用 python selenium 读取、写入和控制动态实例化的 HTML web 表
- angular - 当我路由到不同的组件时,我可以在 Angular 7 的后台调用 api 服务吗