Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"takeWhile is not a function" while using with IntervalObservable

I have this simple setup in my Angular 2 code:

IntervalObservable.create(5000)
  .takeWhile(() => this.spinnerOn) // only fires when component is alive
  .subscribe(() => {
    this.httpService.pollResults()
      .subscribe(data => {
        console.log(data);
      });
  });

The code compiles, and i can see the takeWhile.d.ts used from rxjs node module in my IDE (IDEA). But when the app runs, i see this error in the console:

ERROR TypeError: __WEBPACK_IMPORTED_MODULE_3_rxjs_observable_IntervalObservable__.a.create(...).takeWhile is not a function

What am i doing wrong?

like image 571
akcasoy Avatar asked Nov 19 '17 08:11

akcasoy


1 Answers

you need to import the takeWhile operator:

import 'rxjs/add/operator/takeWhile';

If you are using rxjs 5.5 and above

import { takeWhile } from 'rxjs/operators';
like image 93
Sajeetharan Avatar answered Oct 13 '22 09:10

Sajeetharan