Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度7清除输入字段_Angular_Input_Checkbox - Fatal编程技术网

Angular 角度7清除输入字段

Angular 角度7清除输入字段,angular,input,checkbox,Angular,Input,Checkbox,我正在angular中创建一个表单,其中有一个复选框和两个输入字段。我想使输入字段被禁用,并在选中复选框时进行清理。我设法做了禁用部分,但当字段被禁用时,它们仍然得到了它们的值。我怎样做清洁部分?我只找到了用按钮或angularJs之类的东西来做的方法,但这些都不适合我 HTML代码: 格式化HTML //表单的其他部分// 关闭 打开 此字段必填 开放给 此字段必填 检查此项 @组件({ 选择器:“我的应用程序”, templateUrl:“./app.component.html”, 样式U

我正在angular中创建一个
表单
,其中有一个
复选框
和两个
输入
字段。我想使
输入
字段
被禁用
,并在选中
复选框
时进行清理。我设法做了禁用部分,但当字段被禁用时,它们仍然得到了它们的值。我怎样做清洁部分?我只找到了用按钮或angularJs之类的东西来做的方法,但这些都不适合我

HTML代码: 格式化HTML

//表单的其他部分//
关闭
打开
此字段必填
开放给
此字段必填
检查此项

@组件({
选择器:“我的应用程序”,
templateUrl:“./app.component.html”,
样式URL:['./app.component.css']
})
导出类AppComponent{
@ViewChild('input',{static:false})input:ElementRef
onChange(事件:MouseEvent){
让target=event.target作为HTMLInputElement
if(target.checked){
this.input.nativeElement.value=“”
}
}
}
//app.component.html

更改发射器时使用mat复选框。在组件函数中,使用表单组执行以下值清理操作

 onChange(args) {
  if(args.isChecked){
   this.editForm.get('openFrom').patchValue(null);
   this.editForm.get('openTo').patchValue(null);
  }
}

请编写您的html代码以帮助您更好地完成任务。谢谢:)