我正在写一个 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>
谁能看到我做错了什么?谢谢!
原文由 RainOnMe77 发布,翻译遵循 CC BY-SA 4.0 许可协议
将您的代码从
<input class="toggle" type="checkbox" [(ngModule)]="todo.isDone" >
更改为…在这里,ngModule 没有识别..