This happens because when you change valueAccessor Angular doesn’t register onChange and onTouched events on that new component again.

What you can try as workaround is to register those events manually:

const ngControl = this.injector.get(NgControl);
const valueAccessor = ngControl.valueAccessor as any;
if (valueAccessor && valueAccessor.onChange) {
  this.componentRef.instance.registerOnChange(valueAccessor.onChange);
  this.componentRef.instance.registerOnTouched(valueAccessor.onTouched);
}
ngControl.valueAccessor = this.componentRef.instance;

Forked Stackblitz

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top