我正在尝试绑定我的输入以显示字符串。但我有这个错误:
错误:list.component.html:3:15 - 错误 TS2322:“事件”类型不可分配给“字符串”类型。.
3 [(ngModel)]="todoItem" ~~~~~~~~~ 4 (keyup) ="addTodo()"
src/app/components/todo-list/todo-list.component.ts:5:16
5 templateUrl: './todo-list.component.html',
todo-list.componentn.html :
<input type="text"
placeholder="What needs to be done"
[(ngModel)]="todoItem"
/>
<div class="item-left" *ngFor="let todo of todos">
<input type='checkbox' >
<p>{{todo.title}}</p>
</div>
todo-list.component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-todo-list',
templateUrl: './todo-list.component.html',
styleUrls: ['./todo-list.component.css'],
})
export class TodoListComponent implements OnInit {
todos!: Todos[];
todoItem!: string;
constructor() {}
ngOnInit(): void {
this.todoItem = '';
this.todos = [
{
id: 1,
title: 'Surya',
}, …Run Code Online (Sandbox Code Playgroud)