Reputation: 1030
Is there a way to set emitEvent to false to all forms controls ?
For the moment, when we patchValue or setValue, it is possible to pass options to not throw the valueChanges of a form:
form.get['myControlName'].setValue('newValue', {emitEvent:false})
form.get['myControlName'].patchValue('newValue', {emitEvent:false})
But if we have a lot of patchValue or setValue, it is a bit repetitive... I there a way to disable the emitEvent before, change all values and active it again after ?
Upvotes: 0
Views: 2810
Reputation: 3297
you can use a simple solution like this :
iterate on all controls of you form and reset their value and set the emitEvent
to 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});
}
hope it helps :)
Upvotes: 1