我正在使用createSelector函数
我有一个我无法解决的问题,我已经达到了一个我不知道该怎么做的地步
export const getRecoveryIsOpen = createSelector(
getRecoveryPasswordState,
fromRecoveryPassword.getRecoveryPasswordIsOpen
)
所以我叫她
this.store.select(reducers.getRecoveryState).subscribe( isBlur => {
console.log(isBlur)
})
在任何时候都不能正常工作。 y en el Redux devtools estan los estados cargados Correctamente
ERROR TypeError: Cannot read property 'isOpen' of undefined
at getRecoveryPasswordIsOpen (recovery-password.reducer.ts:65)
at store.js:938
at memoized (store.js:853)
at defaultStateFn (store.js:893)
at store.js:947
at memoized (store.js:853)
at MapSubscriber.project (store.js:772)
at MapSubscriber._next (map.js:29)
at MapSubscriber.next (Subscriber.js:49)
at MapSubscriber._next (map.js:35)
这是我的recovery-password.reducer
import * as RecoveryPasswordActions from '../actions/recovery-password.actions';
import { RecoveryPasswordActionTypes } from '../actions/recovery-password.actions';
export interface State {
identificacion: number;
error: String;
currentStep: number;
isOpen: boolean;
}
const initialState: State = {
identificacion: null,
error: "",
currentStep: 1,
isOpen: false
}
export function RecoveryPasswordReducer(state: State = initialState, action: RecoveryPasswordActions.actions) {
switch (action.type) {
case RecoveryPasswordActionTypes.OpenRecoveryPassword:
return {
...state,
isOpen: true
}
case RecoveryPasswordActionTypes.CloseRecoveryPassword:
return {
...state,
isOpen: false
}
case RecoveryPasswordActionTypes.SendIdUser:
return {
...state,
identificacion: action.payload.identificacion
}
case RecoveryPasswordActionTypes.SendIdUserError:
return {
...state,
error: action.payload.error
}
case RecoveryPasswordActionTypes.SendIdUserSuccess:
return {
...state,
currentStep: 2
}
case RecoveryPasswordActionTypes.SendRecoveryMethod:
return {
...state,
recoveryMethod: action.payload.recoveryMethod
}
default:
return state;
}
}
export const getRecoveryPasswordState = (state: State) => state;
export const getRecoveryPasswordIsOpen = (state: State) => state.isOpen;
export const getRecoveryPasswordCurrentStep = (state: State) => state.currentStep;
export const getRecoveryPasswordError = (state: State) => state.error;
我复习了很多,我真的没有发现任何错误,我想知道我做错了什么。
答案 0 :(得分:1)
export const selectIsOpen = createFeatureSelector<boolean>('isOpen'); // if you dont have any name for module AppModule or this is not Child StroreModule
export const selectPatent = createFeatureSelector<State>('Parent name'); // parent name you can find in parant Module in imports StoreModule.forFeature('Parent name', reducers)
export const export const getRecoveryIsOpen = createSelector(selectPatent, (state) => state && state.isOpen);