类型"Observable< User>"上不存在属性"switchMap" [英] Property 'switchMap' does not exist on type 'Observable<User>'
问题描述
尝试将switchMap运算符应用于我的Observable时,我收到以下错误消息:
I have been getting the following error message when trying to apply the switchMap operator to my Observable:
可观察"类型不存在属性"switchMap".
Property 'switchMap' does not exist on type 'Observable'.
我当前正在使用rxjs版本5.5.2,在我的组件中,我将其导入为:
I'm currently using rxjs version 5.5.2, and in my component, I have it imported like so:
import 'rxjs/operator/switchMap';
但是,我仍然遇到编译错误.我已经看过类似的问题,却没有找到合适的解决方案,关于这里可能出现的问题有什么建议吗?
However, I still get a compilation error. I have looked at similar questions and have not found a proper solution to this, any suggestions on what could be the issue here?
get appUser$() : Observable<AppUser> {
return this.user$
.switchMap(user => {
if (user) return this.userService.get(user.uid);
return Observable.of(null);
});
}
图片:
推荐答案
如果您使用的是较旧的"patch"样式的运算符,则应从rxjs/add/operator/switchMap
导入:
You should be importing from rxjs/add/operator/switchMap
if you're using the older "patch" style of operators:
import 'rxjs/add/operator/switchMap';
由于RxJS 5.5具有可点入"运算符,因此您应该从'rxjs/operators'
导入:
Since RxJS 5.5 with "pipable" operators you should import from 'rxjs/operators'
:
import { switchMap } from 'rxjs/operators';
这篇关于类型"Observable< User>"上不存在属性"switchMap"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!