更新时间:2022-06-12 05:17:51
您的代码有几个问题:
指令需要返回值,以便可以绑定到相应的表单控件:
export class NullValueDirectiveDirective {
@Output('EmptyToNull') response = new EventEmitter<string>();
@HostListener('keyup', ['$event']) onKeyDowns(event: KeyboardEvent) {
this.response.emit(null);
}
}
接下来,您需要绑定模板到发射的值:
<input formControlName="AuthorityNum"
(EmptyToNull) = "form.controls.AuthorityNum.value = $event">