Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 987
Nehal Jaisalmeria Avatar asked Oct 14 '25 04:10

Nehal Jaisalmeria


1 Answers

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

Try this:

 this.addModelForm.patchValue( { domain: '' },{emitEvent: false}); 
like image 109
Chellappan வ Avatar answered Oct 18 '25 09:10

Chellappan வ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!