我的效果是,我想根据存储中的某些值有条件地进行数据调用。像这样:
@Effect()
loadRequestEffect$: Observable<Action> = this.actions$.pipe(
ofType<actions.RegisterDataSubscription>,
withLatestFrom(
this.store.select(dataManagementFeature)
),
switchMap(([action, data]) => {
if (...condition...) {
return this.http
.get()
.pipe(
map(data => new actions.SetEndpointData()),
);
}
else {
return of(new actions.SetEndpointLoading());
}
})
我以为我可以在switchMap中“执行”新动作,但显然不能。它不会编译此投诉:
ERROR in src/app/store/data-management-store/effects.ts(22,15): error TS2345: Argument of type '([action, data]: [RegisterDataSubscription, State]) => Observable<SetEndpointData> | Observable<SetEndpointLoading>' is not assignable to parameter of type '(value: [RegisterDataSubscription, State], index: number) => ObservableInput<SetEndpointData>'.
Type 'Observable<SetEndpointData> | Observable<SetEndpointLoading>' is not assignable to type 'ObservableInput<SetEndpointData>'.
有什么建议吗?