【发布时间】:2020-09-11 09:59:17
【问题描述】:
我正在尝试在自定义 Angular Material Form Field Control 中访问 NgControl:
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();
});
}
但是当我这样做时,我使用组件的界面是空白的,没有错误! 当我从构造函数中移除 NgControl 时,视图被渲染。
这就是注入NgControl的方式吗?
提前致谢。
【问题讨论】: