简体   繁体   中英

“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?

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM