import { Component , ElementRef , forwardRef , OnChanges , OnInit , ViewChild , Input , } from '@angular/core' ; import { FormBuilder } from '@angular/forms' ; import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ; export const FORM_INPUT_CHECKBOX_VALUE_ACCESSOR = { provide : NG_VALUE_ACCESSOR , useExisting : forwardRef ( ( ) => FormInputCheckboxComponent ) , multi : true , } ; @ Component ( { selector : 'm-formInput__checkbox' , templateUrl : 'checkbox.component.html' , providers : [ FORM_INPUT_CHECKBOX_VALUE_ACCESSOR ] , } ) export class FormInputCheckboxComponent implements ControlValueAccessor { readonly id : string ; value : boolean = false ; @ Input ( ) disabled : boolean = false ; @ ViewChild ( 'input' , { static : true } ) input : ElementRef ; updateValue ( value ) { this . value = value ; this . propagateChange ( this . value ) ; } propagateChange = ( _ ) => { } ; constructor ( private fb ) { this . id = `checkbox` + Math . random ( ) . toString ( 36 ) . substring ( 2 ) ; } writeValue ( value ) { this . value = value ; } registerOnChange ( fn ) { this . propagateChange = fn ; } registerOnTouched ( fn ) { } }