Home > Mobile >  ControlValueAccessor and FormControl Value are out of sync
ControlValueAccessor and FormControl Value are out of sync

Time:10-25

I have implemented a mask on my input to allow only a special format. The mask is working correctly, but when the user enters letters, for example, it is attached to the formControl value, even when the field does not show it.

Stackblitz

CodePudding user response:

accessor.writeValue is a way to update the value inside of the input, but not in the logical model. The shortest fix is

if(newVal != event) this.ngControl.control.setValue(newVal);

this will update the value inside of the control

  • Related