【发布时间】:2017-11-30 02:12:43
【问题描述】:
switchMap 运算符有错误:
@Injectable()
export class AvailableStoreTypesLoadedEffect {
constructor(private actions$: Actions,
private service: AvailableService) {
}
@Effect()
AvailableStoreTypesLoadedEffect$ = this.actions$
.ofType(FETCH_AVAILABLE_STORE_TYPES)
.pipe(
switchMap(action => this.service.fetchAvailableStoreTypes()),//Error:(22, 9) TS2684:The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'.
map(res => new AvailableStoreTypesLoaded(res))
);
}
我试过了:
Observable.of({})
.pipe(
switchMap(() => Observable.of({}))//Error:(22, 9) TS2684:The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'.
);
但我得到了同样的错误。
我的环境是:
- 角度5.0.3
- 打字稿 2.4.2
- rxjs 5.5.2
【问题讨论】:
-
你的
this.service.fetchAvailableStoreTypes()是否返回了一个 observable? -
是的,我回
return Observable.of({}); -
我试过了:
Observable.of({}) .pipe( switchMap(() => Observable.of({})) );,我得到了同样的错误 -
如果您可以发布比这更多的代码,我认为这对您理解您的问题非常有帮助。查看
pipe被调用的内容、fetchAvailableStoryTypes的外观以及AvailableStoryStypesLoaded的外观将特别有帮助。 -
我用更多数据编辑了帖子。