In my setup, the parent component is utilizing a FormGroup and I am expecting the child components to notify any changes in value back to the parent. To achieve this, I am trying to implement NG_VALUE_ACCESSOR in the child component so that it can act like a form field. I believe that one needs to utilize the following 4 functions:
writeValue(value) {
this.value = value;
}
registerOnChange(fn: any) {
this.onChange = fn;
}
registerOnTouched(fn: any) {
this.onTouch = fn;
}
setDisabledState?(isDisabled: boolean): void {
this.isDisabled = isDisabled;
}
to make the child component behave like a form field. However, my current solution is not working as expected:
https://stackblitz.com/edit/angular-ivy-tpneik?file=src%2Fapp%2Fapp.component.ts
The error message I am currently encountering is:
Error: No value accessor for form control with path: 'ok -> isChecked'
My objective is to have a child component (and possibly more) that can accurately report its value changes to the parent form residing in the parent component. How should I go about addressing this issue?