I am trying to access NgControl within a custom Angular Material Form Field Control:
constructor(
@Self() @Optional() public ngControl: NgControl,
private fb: FormBuilder,
private fm: FocusMonitor,
private elRef: ElementRef<HTMLElement>
) {
this.createForm();
console.log('<< ', this.ngControl);
if (this.ngControl != null) {
this.ngControl.valueAccessor = this;
}
fm.monitor(elRef.nativeElement, true).subscribe(origin => {
this.focused = !!origin;
this.stateChanges.next();
});
}
But when I do this the interface where I use the component is blank, no errors! When I remove the NgControl from the constructor the view is rendered.
Is that the way to inject NgControl?
Thanks in advance.