import { Directive , ElementRef , forwardRef , HostListener , Provider , Renderer2 } from '@angular/core' ; import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ; ignore const NGQP_CHECKBOX_VALUE_ACCESSOR = { provide : NG_VALUE_ACCESSOR , useExisting : forwardRef ( ( ) => CheckboxControlValueAccessorDirective ) , multi : true } ; ignore @ Directive ( { selector : 'input[type=checkbox][queryParamName],input[type=checkbox][queryParam]' , providers : [ NGQP_CHECKBOX_VALUE_ACCESSOR ] , } ) export class CheckboxControlValueAccessorDirective implements ControlValueAccessor { private fnChange = ( _ ) => { } ; private fnTouched = ( ) => { } ; @ HostListener ( 'change' , [ '$event' ] ) public onInput ( event ) { this . fnChange ( ( event . target as HTMLInputElement ) . checked ) ; } @ HostListener ( 'blur' ) public onBlur ( ) { this . fnTouched ( ) ; } constructor ( private renderer , private elementRef ) { } public writeValue ( value ) { this . renderer . setProperty ( this . elementRef . nativeElement , 'checked' , value ) ; } public registerOnChange ( fn ) { this . fnChange = fn ; } public registerOnTouched ( fn ) { this . fnTouched = fn ; } public setDisabledState ( isDisabled ) { this . renderer . setProperty ( this . elementRef . nativeElement , 'disabled' , isDisabled ) ; } }