html - 错误 TS2322:类型“事件”不可分配给类型“布尔”
问题描述
我正在写一个 todolist 演示。当ng serve
它出现时,它显示一个错误:
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>
~~
也不会检查所有项目。(即使它们的 isDone 状态为真)
我在 app.component.ts 中定义了一个对象。
public todos:{
id:number,
title: string,
isDone: boolean
}[]=todos
const todos=[
{
id:1,
title:'study',
isDone:true
},{
id:2,
title:'sleep',
isDone:true
},{
id:3,
title:'drink',
isDone:true
}
]
app.component.html 如下。
<li *ngFor="let todo of todos">
<div class="view">
<input class="toggle" type="checkbox" [(ngModule)]="todo.isDone" >
<label>{{ todo.title }}</label>
<button class="destroy"></button>
</div>
<input class="edit" value="Create a TodoMVC template">
</li>
谁能看到我做错了什么?谢谢!
解决方案
当我收到此错误时,是因为我忘记导入FormsModule
in app.module.ts
。所以在 app.module.ts 中:
import { FormsModule } from '@angular/forms';
...
imports: [
..,
FormsModule
],
推荐阅读
- c# - 如何获得表格的正确宽度?
- tableau-api - 表格计算字段中的 IF 部分未执行
- javascript - Angular ng-repeat 导致多个循环
- javascript - Firebase 实时数据库和 HTTP 请求:多轴上的复杂查询
- hyperledger-fabric - Hyperledger Fabric v1.3 - 共识
- svg - 带有过滤器的 SVG 图像 - 过滤器覆盖的区域大于图像
- matlab - 迭代求解非线性方程
- architecture - 是对等软件架构还是只是一种模式?
- caching - 如何从 EaselJS / CreateJS 中的缓存对象以外的源绘制到 cacheCanvas?
- r - 如何使用日期作为过滤器