[英]“takeWhile is not a function” while using with IntervalObservable
I have this simple setup in my Angular 2 code: 我在Angular 2代码中有这个简单的设置:
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). 代码编译,我可以看到我的IDE(IDEA)中的rxjs节点模块使用的takeWhile.d.ts。 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: 你需要导入
takeWhile
运算符:
import 'rxjs/add/operator/takeWhile';
If you are using rxjs 5.5 and above 如果您使用的是rxjs 5.5及以上版本
import { takeWhile } from 'rxjs/operators';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.