import { Directive , ElementRef , HostListener , Input , Optional , Self } from '@angular/core' ; import { FormGroupDirective , NgControl } from '@angular/forms' ; import { FormFieldControl } from '../form-field/form-field-control' ; let uniqueId = 0 ; @ Directive ( { selector : 'input[gdInput], textarea[gdInput]' , providers : [ { provide : FormFieldControl , useExisting : InputDirective , } , ] , host : { 'class' : 'Input' , '[attr.id]' : 'id' , } , } ) export class InputDirective extends FormFieldControl { private _id = `gd-input-${ uniqueId ++ }` ; @ Input ( ) get id ( ) { return this . _id ; } set id ( value ) { this . _id = value ; } constructor ( @ Self ( ) public ngControl , @ Optional ( ) public parentForm , public elementRef ) { super ( ) ; } @ HostListener ( 'focus' ) private handleFocus ( ) { this . focused = true ; } @ HostListener ( 'blur' ) private handleBlur ( ) { this . focused = false ; } }