8

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?

1 Answer 1

23

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';
Sign up to request clarification or add additional context in comments.

3 Comments

this was the fastest true answer i got till now :) thanks !!
I'm using rxjs 5.5.2 and 2nd import didn't work for me. Used the first approach
I am using the same 'v5.5.2' and got the error for the second. First one solved it for me too. Thanks @Sajeetharan and Nouman

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.