-
-
Notifications
You must be signed in to change notification settings - Fork 109
Description
Problem
Currently, when using NgxControlValueAccessor, there is no clean or ergonomic way to override the writeValue method in order to apply custom logic when the parent component sets a value. While it is technically possible to manually override writeValue like this:
this.cva.writeValue = (value: unknown) => {
// custom implementation
};
this approach feels hacky and fragile, as it directly mutates the method after initialization.
Proposal
It would be beneficial to introduce an injection token or a similar configuration mechanism that allows developers to cleanly provide custom writeValue logic. This would enhance flexibility and maintainability, especially in complex form scenarios where value preprocessing or transformation is necessary before updating the internal state. As it lacks support of component's method alternative solution consider introducing a public state flag or callback in NgxControlValueAccessor to indicate when a value update originates from the parent (writeValue) vs from internal component interaction (onChange()).
Benefits
- Enables custom behavior when value is set from parent.
- Avoids monkey-patching or unsafe overrides.
- Seperate logic for value written from formGroup and manually updated by user