23 lines
455 B
TypeScript
23 lines
455 B
TypeScript
|
import {Directive, HostListener, Input} from "@angular/core";
|
||
|
|
||
|
@Directive({
|
||
|
selector: '[focus-directive]',
|
||
|
})
|
||
|
export class FocusDirective {
|
||
|
@Input('formInput') formControl: any;
|
||
|
|
||
|
constructor() { }
|
||
|
|
||
|
@HostListener
|
||
|
('focus', ['$event.target'])
|
||
|
onFocus(target) {
|
||
|
this.formControl.markAsTouched({onlySelf: true});
|
||
|
}
|
||
|
|
||
|
@HostListener('blur', ['$event.target'])
|
||
|
onBlur(target) {
|
||
|
this.formControl.markAsUntouched({onlySelf: true});
|
||
|
}
|
||
|
|
||
|
}
|