In some cases when I update an Angular2 Form control, I don't want to fire the valueChanges event (e.g. because the change is coming reactively from my database and shouldn't trigger a database write to avoid an infinite loop).
That works great with standard FormControls using the "emitEvent" property like this:
this.form.formGroup.controls[name].setValue(value, {emitEvent: false});
Now I have a case, where I want to use that "feature" on a custom FormControl which I created implementing the "ControlValueAccessor" with it's registerOnChange() and writeValue() methods.
But I don't know how to access the emitEvent Property, since it's not an incoming parameter in the writeValue()
Is there a way to achieve that? Thanks!
This isn't how it works, writeValue is what Angular uses to update your custom component, not the other way around. The control gets updated using a function that was passed to registerOnChange, however this is for updating value through the UI of your component, it cannot be done without emitting an event and really there is no case for that. If you tell more about your situation, we can try to work it out. If you want to prevent extra save requests, you can add debounce mechanism or use Angular FormHooks — 'blur' will update control only after you leave the UI element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With