我输入输入字段如下:
<input mdInput placeholder="Name" #filterName name="filterName" >
我想清除点击清除按钮的价值:
<button (click)="clearFilters()">Clear</button> app.component.ts function : filterName : string = null; clearFilters() { this.filterName = ''; }
请告诉我上面的错误,因为它不适合我.
这里是jsfiddle https://jsfiddle.net/8fw8uq3x/
你可以做这样的事情
原文链接:https://www.f2er.com/angularjs/140977.html<input placeholder="Name" #filterName name="filterName" /> <button (click) = "filterName.value = ''">Click</button>
要么
模板
<input mdInput placeholder="Name" [(ngModel)]="filterName" name="filterName" > <button (click) = "clear()'">Click</button>
在组件中
filterName:string; clear(){ this.filterName = ''; }
更新
如果是表格
清除表单以及错误状态(脏,prestine等)的最简单,最干净的方法
this.form_name.reset();
有关表格的更多信息,请阅读此处
https://angular.io/docs/ts/latest/guide/forms.html
PS: As you asked question there is no form used in your question code
you are using simple two day data binding using ngModel not with
formControl.form.reset() method works only for formControls reset call