我正在学习如何在angular 7中使用ngrx store。当我调度一个动作来存储细节时,它会引发错误
Cannot read property 'concat' of undefined at todolistReducer.
在减速器文件中。请帮助
// todolist.reducer.ts
import { Todo } from '../../todo';
import { Action } from '@ngrx/store';
import * as ToDoListAction from '../actions/todolist.action';
const initialState = {
todoList: Todo['']
};
export function todolistReducer(state = initialState, action: ToDoListAction.AddTodoList) {
switch (action.type) {
case ToDoListAction.ADD_TODOLIST:
return {
...state,
todoList: [...state.todoList, action.payload]
};
default:
return state;
}
}
// component.ts
this.storeObj.dispatch(new todoListActions.AddTodoList(obj));