import { Directive , HostListener , forwardRef } from '@angular/core' ; import { DefaultValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ; const TRIM_VALUE_ACCESSOR = { provide : NG_VALUE_ACCESSOR , useExisting : forwardRef ( ( ) => TrimValueAccessor ) , multi : true } ; /**
 * The trim accessor for writing trimmed value and listening to changes that is
 * used by the  NgModel ,  FormControlDirective , and
 *  FormControlName directives.
  @ Directive ( { selector : `
    input:not([type=checkbox]):not([type=radio]):not([type=password]):not([readonly]):not(.ng-trim-ignore)[formControlName],
    input:not([type=checkbox]):not([type=radio]):not([type=password]):not([readonly]):not(.ng-trim-ignore)[formControl],
    input:not([type=checkbox]):not([type=radio]):not([type=password]):not([readonly]):not(.ng-trim-ignore)[ngModel],
    textarea:not([readonly]):not(.ng-trim-ignore)[formControlName],
    textarea:not([readonly]):not(.ng-trim-ignore)[formControl],
    textarea:not([readonly]):not(.ng-trim-ignore)[ngModel],
    :not([readonly]):not(.ng-trim-ignore)[ngDefaultControl]
  ` , providers : [ TRIM_VALUE_ACCESSOR ] } ) export class TrimValueAccessor extends DefaultValueAccessor { @ HostListener ( 'input' , [ '$event.target.value' ] ) ngOnChange = ( val ) => { this . onChange ( val . trim ( ) ) ; } ; @ HostListener ( 'blur' , [ '$event.target.value' ] ) ngOnBlur = ( val ) => { this . writeValue ( val . trim ( ) ) ; this . onTouched ( ) ; } ; writeValue ( value ) { if ( typeof value === 'string' ) { value = value . trim ( ) ; } super . writeValue ( value ) ; } }