import { Directive , ElementRef , forwardRef , HostListener , Inject , Optional , PLATFORM_ID , Provider , Renderer2 } from '@angular/core' ; import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ; import { isPlatformBrowser } from '@angular/common' ; ignore const NGQP_DEFAULT_VALUE_ACCESSOR = { provide : NG_VALUE_ACCESSOR , useExisting : forwardRef ( ( ) => DefaultControlValueAccessorDirective ) , multi : true } ; ignore function isAndroid ( navigator ) { return /android (\d+)/ . test ( navigator . userAgent . toLowerCase ( ) ) ; } ignore @ Directive ( { selector : 'input:not([type=checkbox]):not([type=radio])[queryParamName],textarea[queryParamName],' + 'input:not([type=checkbox]):not([type=radio])[queryParam],textarea[queryParam]' , providers : [ NGQP_DEFAULT_VALUE_ACCESSOR ] , } ) export class DefaultControlValueAccessorDirective implements ControlValueAccessor { private readonly supportsComposition : boolean ; private composing = false ; private fnChange = ( _ ) => { } ; private fnTouched = ( ) => { } ; @ HostListener ( 'input' , [ '$event' ] ) public onInput ( event ) { if ( this . supportsComposition && this . composing ) { return ; } this . fnChange ( ( event . target as HTMLInputElement ) . value ) ; } @ HostListener ( 'blur' ) public onBlur ( ) { this . fnTouched ( ) ; } @ HostListener ( 'compositionstart' ) public onCompositionStart ( ) { this . composing = true ; } @ HostListener ( 'compositionend' , [ '$event' ] ) public onCompositionEnd ( event ) { this . composing = false ; if ( this . supportsComposition ) { this . fnChange ( ( event . target as HTMLInputElement ) . value ) ; } } constructor ( @ Optional ( ) @ Inject ( PLATFORM_ID ) private platformId , private renderer , private elementRef ) { this . supportsComposition = isPlatformBrowser ( this . platformId || '' ) && ! isAndroid ( window . navigator ) ; } public writeValue ( value ) { const normalizedValue = value === null ? '' : value ; this . renderer . setProperty ( this . elementRef . nativeElement , 'value' , normalizedValue ) ; } public registerOnChange ( fn ) { this . fnChange = fn ; } public registerOnTouched ( fn ) { this . fnTouched = fn ; } public setDisabledState ( isDisabled ) { this . renderer . setProperty ( this . elementRef . nativeElement , 'disabled' , isDisabled ) ; } }