NgRx Reducer 道具值始终未定义
NgRx Reducer props value is always undefined
我有一个 returns 数据正确的效果,我正在使用效果中的数据调用一个动作,但减速器 "detailsList" 始终未定义。
效果调用CustomAction.ShowDetails(道具数据)
效果
response.student.details always has data so the response is correct
if (response === "test") {
return of(CustomAction.ShowDetails(response.student.details));
}
减速器
export interface StudentState {
newStudentDetails: any[];
}
export const studentInitialState: StudentState = {
newStudentDetails: null;
};
const reducer = createReducer(
studentInitialState,
on(CustomAction.ShowDetails, (state, { detailsList}) => ({
...state,
newStudentDetails: detailsList
})),
);
export function createStudentReducer(
state: StudentState,
action: Action
) {
return reducer(state, action);
}
detailsList 始终未定义
动作
export const ShowDetails = createAction(
CustomActionTypes.ShowDetails,
props<{ detailsList: any[] }>()
);
我在调试reducer的时候,detailslist总是undefined。有什么想法吗?
你必须在你的效果中做这样的事情:
return of(CustomAction.ShowDetails({detailsList: response.student.details}));
我有一个 returns 数据正确的效果,我正在使用效果中的数据调用一个动作,但减速器 "detailsList" 始终未定义。
效果调用CustomAction.ShowDetails(道具数据)
效果
response.student.details always has data so the response is correct
if (response === "test") {
return of(CustomAction.ShowDetails(response.student.details));
}
减速器
export interface StudentState {
newStudentDetails: any[];
}
export const studentInitialState: StudentState = {
newStudentDetails: null;
};
const reducer = createReducer(
studentInitialState,
on(CustomAction.ShowDetails, (state, { detailsList}) => ({
...state,
newStudentDetails: detailsList
})),
);
export function createStudentReducer(
state: StudentState,
action: Action
) {
return reducer(state, action);
}
detailsList 始终未定义
动作
export const ShowDetails = createAction(
CustomActionTypes.ShowDetails,
props<{ detailsList: any[] }>()
);
我在调试reducer的时候,detailslist总是undefined。有什么想法吗?
你必须在你的效果中做这样的事情:
return of(CustomAction.ShowDetails({detailsList: response.student.details}));