Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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
Forms 如何对所有窗体控件禁用emitEvent_Forms_Angular - Fatal编程技术网

Forms 如何对所有窗体控件禁用emitEvent

Forms 如何对所有窗体控件禁用emitEvent,forms,angular,Forms,Angular,是否有方法将所有窗体控件的emitEvent设置为false 目前,当我们修补Value或setValue时,可以传递选项以不引发窗体的valueChanges: form.get['myControlName'].setValue('newValue', {emitEvent:false}) form.get['myControlName'].patchValue('newValue', {emitEvent:false}) 但是如果我们有很多patchValue或setValue,它有点重

是否有方法将所有窗体控件的emitEvent设置为false

目前,当我们修补Value或setValue时,可以传递选项以不引发窗体的valueChanges:

form.get['myControlName'].setValue('newValue', {emitEvent:false})
form.get['myControlName'].patchValue('newValue', {emitEvent:false})

但是如果我们有很多patchValue或setValue,它有点重复。。。我有办法在之前禁用emitEvent,更改所有值并在之后再次激活它?

您可以使用如下简单解决方案: 迭代窗体的所有控件并重置其值,然后将
emitEvent
设置为
false

//the "manual" solution :
form.controls['name'].setValue('nameNewValue', {emitEvent:false});
form.controls['address'].setValue('addressNewValue', {emitEvent:false});

// the "dynamic" solution
for(let control in form.controls){            
    form.controls[control].setValue(form.controls[control].value, {emitEvent:false});
}
希望有帮助:)