For some reason I can't use the takeUntil
method on any of my observables.
My IDE (Visual Studio Code) shows it as a valid method while I'm coding, and it compiles fine (from typescript), but when I run it I get takeUntil is not a function
on any of my observables.
I'm using rxjs version 5.3.0.
I can make it happen in a wide variety of ways, but this is likely the most straightforward:
let subject:BehaviorSubject<any> = new BehaviorSubject<any>({});
let unsubscribe: Subject<void> = new Subject<void>();
subject.takeUntil(unsubscribe);
Honestly I can't find any way to instantiate anything where takeUntil
doesn't result in that error, but the IDE never complains and typescript always compiles fine - the error always occurs in the browser.
What is TakeUntil. The takeUntil operator is used to automatically unsubscribe from an observable. takeUntil begins mirroring the source Observable. It also monitors a second Observable, notifier that you provide. If the notifier emits a value, the output Observable stops mirroring the source Observable and completes.
takeUntil passes values from the source observable to the observer (mirroring) until a provided observable known as the notifier emits its first value. The operator subscribes to the source observable and begins mirroring the source Observable. It also subscribes to the notifier observable.
The takeUntil(notifier) keeps emitting the values until it is notified to stop. takeWhile(predicate) emits the value while values satisfy the predicate.
I found an easier way to do this for my use case, If you want to do something when the observable is complete then you can use this: const subscription$ = interval(1000). pipe( finalize(() => console. log("Do Something")), ).
you probably need to import the takeUntil operator:
import 'rxjs/add/operator/takeUntil';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With