首页 > 解决方案 > 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>?

标签: angularrxjscombinelatest

解决方案


如果要将结果合并到单个流中,请使用merge() from 'rxjs'. 如果要对两者执行逻辑操作:

结合最新接受的项目函数作为最后一个参数,例如 combineLatest(obs1$, obs2$, ([first, second]) => first || second) ;

它已被弃用。所以你需要使用map.

combineLatest(obs1$, obs2$,).pipe(
    map([first, second]) => first || second)
);

推荐阅读