错误TS2322:“事件”类型不可分配给“布尔值”类型
我正在写一个 todolist 演示。当ng serve它,它显示一个错误:
Error: src/app/app.component.html:17:58 - error TS2322: Type 'Event' is not assignable to type 'boolean'.
17 <input type="checkbox" [(ngModule)]="todo.isDone" >
~~~~~~~~~~~~~~
18
19 <label>{{ todo.title }}</label>
~~
也不会检查所有项目。(即使它们的 isDone 状态为真)
我在 app.component.ts 中定义了一个对象。
Error: src/app/app.component.html:17:58 - error TS2322: Type 'Event' is not assignable to type 'boolean'.
17 <input class="toggle" type="checkbox" [(ngModule)]="todo.isDone" >
~~~~~~~~~~~~~~
18
19 <label>{{ todo.title }}</label>
~~
回答
当我收到此错误时,是因为我忘记导入FormsModulein app.module.ts. 所以在 app.module.ts 中:
import { FormsModule } from '@angular/forms';
...
imports: [
..,
FormsModule
],