patchValue with { emitEvent: false, onlySelf: true } triggers valueChanges in Angular

Viewed 1494

I have a Reset button which resets the value of domain with patchValue

onReset() {      
    this.addModelForm.patchValue({ domain: '', emitEvent: false, onlySelf: true}); 
}

and this is the valueChanges method for domain :

this.addModelForm.get('domain').valueChanges.subscribe(domainId => {
    console.log("value changed!")
});

It prints "value changed!" on console 2 times. I don't want to trigger the valueChanges method. emitEvent is not working.

1 Answers

Since you are using patchValue on FormGroup It should be like this:

Try this:

 this.addModelForm.patchValue( { domain: '' },{emitEvent: false}); 
Related