以角度2重置输入值
发布时间:2020-12-17 08:53:09 所属栏目:安全 来源:网络整理
导读:我输入输入字段如下: input mdInput placeholder="Name" #filterName name="filterName" 我想清除点击清除按钮的价值: button (click)="clearFilters()"Clear/buttonapp.component.ts function :filterName : string = null;clearFilters() {this.filterNa
我输入输入字段如下:
<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/
你可以做这样的事情
<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
一个吸烟者,以显示这将如何工作link. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |