使用Angular和Redux正确处理复选框(ng Redux TODO应用程序)

使用Angular和Redux正确处理复选框(ng Redux TODO应用程序),angular,typescript,redux,Angular,Typescript,Redux,基本上,我试图找出使用Angular+Redux处理复选框的最佳方法 我有一个待办事项列表,希望能够选中/取消选中复选框(将待办事项标记为完成/撤消) 该应用程序运行完美,但每当我想使用跳过/跳转我的changeTodoDone操作时,我就无法(跳转/跳转后对(状态相等)的不同更改) 这是我的模板: <div> <input [(ngModel)]="msg" type="text"> <button (click)="addTodo()">add&l

基本上,我试图找出使用Angular+Redux处理复选框的最佳方法

我有一个待办事项列表,希望能够选中/取消选中复选框(将待办事项标记为完成/撤消)

该应用程序运行完美,但每当我想使用跳过/跳转我的
changeTodoDone操作
时,我就无法(跳转/跳转后对
(状态相等)
的不同更改)

这是我的模板:

<div>
  <input [(ngModel)]="msg" type="text">
  <button (click)="addTodo()">add</button>
</div>
<div *ngFor="let iTodo of iTodos$ | async; let idx = index;">
  <span class="msg">{{iTodo.msg}}</span>
  <input type="checkbox" [ngModel]="iTodo.done" (ngModelChange)="changeTodoDone($event, idx)">
  <button (click)="removeTodo(idx)">remove</button>
</div>
谢谢

@select() readonly iTodos$: Observable<ITodo[]>;

...

changeTodoDone($event, idx: number) {
  this.ngRedux.dispatch(this.actions.changeTodoDone($event, idx));
}
function changeTodoDone(ilastState: IAppState, done: boolean, idxTodo: number): IAppState {
  const iTodos = ilastState.iTodos.map((todo, idx) => {
    if (idxTodo === idx) {
      todo.done = done;
    }
    return todo;
  });
  return { iTodos: iTodos };
}

export function rootReducer(lastState: IAppState, action: ITodoAction): IAppState {
  switch (action.type) {
    case CounterActions.CHANGE_TODO_DONE: return changeTodoDone(lastState, action.done, action.idx);
    case CounterActions.ADD_TODO: return addTodo(lastState, action.text);
    case CounterActions.REMOVE_TODO: return removeTodo(lastState, action.idx);
  }

  // We don't care about any other actions right now.
  return lastState;
}