Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 'takeUntil is not a function' on all my Observables

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.

like image 612
WillyC Avatar asked Apr 20 '17 20:04

WillyC


People also ask

What is takeUntil in RXJS?

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.

What is pipe takeUntil?

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.

What is the difference between takeWhile and takeUntil RXJS operator?

The takeUntil(notifier) keeps emitting the values until it is notified to stop. takeWhile(predicate) emits the value while values satisfy the predicate.

How do you force Observable to complete?

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")), ).


1 Answers

you probably need to import the takeUntil operator:

import 'rxjs/add/operator/takeUntil';

like image 182
JusMalcolm Avatar answered Sep 16 '22 20:09

JusMalcolm