2

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>?

4

2 回答 2

5

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

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

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

combineLatest(obs1$, obs2$,).pipe(
    map([first, second]) => first || second)
);
于 2019-08-20T13:39:18.287 回答
4

我认为您可以forkJoin在此处使用,并且需要使用map运算符将​​这两个可观察值映射为一个值。

forkJoin([observable1, observable2]).pipe(
    map(([bool1, bool2]) => {
        return bool1 & bool2;
    })
);
于 2019-08-20T13:39:39.523 回答