Angular5+中takeWhile is not a function问题求助
问题原因与解决办法
嘿,这个问题我太熟了!你遇到的是RxJS版本升级带来的操作符调用方式变化的问题。
为什么会报错?
从RxJS 6.x版本开始,所有的管道操作符(比如takeWhile、map、filter)都不能直接通过Observable链式调用了,必须要通过.pipe()方法来包裹使用。你现在的代码还是用了RxJS 5.x及更早版本的写法,所以才会抛出takeWhile is not a function的错误。
解决办法
只需要把takeWhile放到pipe()方法里就行,修改后的代码如下:
public ngOnInit(){ this.schemeStore.getSchemesByAffId() .pipe( takeWhile(() => this.isAlive) ) .subscribe((schemes: Scheme[]) => { const currId = schemes[0].currency; this.schemeFunds$ = this.fundStore .getSchemeValorizationsByCurrency(currId); }); }
额外提醒
如果你后续还要使用其他RxJS操作符(比如map、switchMap、filter等),都要遵循这个规则:把所有操作符都放进pipe()方法中,用逗号分隔多个操作符。
内容的提问来源于stack exchange,提问作者Florian
相关产品推荐
相关产品推荐

