如何从指令中获取控件对象而不将任何属性附加到HTML模板? 因为我想控制它的验证状态。
// app.component.html
<form>
<input type="text">
</form>
// input.directive.ts
export class InputDirective {
ngAfterViewInit(): void {
this.setError();
}
private setError(): void {
// If I can get a control object like this...
let control: Control = this.control;
// I can control its validation state.
control.errors['required'] = true;
}
}