小编Sur*_*ddy的帖子

在Angular 4中提交表单后清除输入框

我想在提交表单后清除输入框.

这是我的app.component.ts文件:

todos: string[];

addTodo(todo)
{
   this.todos.push(todo);
   return false;
}
Run Code Online (Sandbox Code Playgroud)

这是我的app.component.html文件

<form (submit)="addTodo(todo.value)">
<input type="text" #todo>
<ul>
<li *ngFor="let todo of todos">{{todo}}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

当我在输入框中填写待办事项,然后按键盘上的回车键或返回键时,它应自动清除我的输入框.

html forms node-modules angular

2
推荐指数
1
解决办法
2823
查看次数

标签 统计

angular ×1

forms ×1

html ×1

node-modules ×1