问题
I am using rxjs 6
I have two observables in my code
import { combineLatest } from 'rxjs/operators';
loading$: Observable<boolean>;
loaded$: Observable<boolean>;
The observables are not coming from http
request but from the store
I need to combine/convert the sequences in to one single observable value based on this logic:
If the sequence true
, true
or false
, false
- need to return new observable true
otherwise need to return false
I tried to use combineLatest
to achieve that:
combineLatest(
this.loaded$, this.loading$,
(val1, val2) => Number(val1) + Number(val2) === 1
)
But the problem is that my combineLatest
returns 'OperatorFunction<>
and not Observable<>
so I cannot subscribe.
Do you have any ideas how to fix that? Or if there is another approach can be taken?
UPDATE:
Seems like that is the answer to my question import { combineLatest } from 'rxjs';
currently testing
回答1:
With RxJS 5.5 it's most likely because you're using combineLatest
from rxjs/operators
while you want to use it as an Observable "creation method" which means you need to use rxjs/observable/combineLatest
.
I mean you need to use this:
import { combineLatest } from 'rxjs/observable/combineLatest';
... instead of this:
import { combineLatest } from 'rxjs/operators';
Edit: Since you mentioned you're using RxJS 6 you can import the static variant from rxjs
.
import { combineLatest } from 'rxjs';
If you're looking for combineLatest
operator you have to import it like this:
import { combineLatest } from 'rxjs/operators';
回答2:
I am guessing I just need this
import { combineLatest } from 'rxjs';
来源:https://stackoverflow.com/questions/50344761/why-combinelatest-returns-operatorfunction-number