После некоторого поиска в Google я нашел два решения:
Решение № 1:
Обратите внимание, что NG_VALUE_ACCESSOR
поставщика нет.
@Component({
selector: 'app-my-input',
templateUrl: './my-input.component.html',
styles: [],
})
export class MyInputComponent implements OnInit, ControlValueAccessor, AfterViewInit {
onChange: (_: any) => void;
onTouched: () => void;
isDisabled: boolean;
value: string;
constructor(private ngControl: NgControl) {
ngControl.valueAccessor = this;
}
ngOnInit() {
console.log('Update On: ', this.ngControl.control.updateOn);
}
}
Решение № 2.
@Component({
selector: 'app-my-input',
templateUrl: './my-input.component.html',
styles: [],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => MyInputComponent),
multi: true,
},
],
})
export class MyInputComponent implements OnInit, ControlValueAccessor, AfterViewInit {
onChange: (_: any) => void;
onTouched: () => void;
isDisabled: boolean;
value: string;
ngControl: NgControl;
constructor(private inj: Injector) {
}
ngOnInit() {
this.ngControl = this.inj.get(NgControl);
}
ngAfterViewInit(): void {
console.log('Update on:', this.ngControl.control.updateOn);
}
}