import { ControlValueAccessor } from '@angular/forms' ; export class ValueAccessorBase < T > implements ControlValueAccessor { private innerValue : T ; private changed = [ ] ; private touched = [ ] ; get value ( ) : T { return this . innerValue ; } set value ( value ) { if ( this . innerValue !== value ) { this . innerValue = value ; this . changed . forEach ( f => f ( value ) ) ; } } touch ( ) { this . touched . forEach ( f => f ( ) ) ; } writeValue ( value ) { if ( value === undefined ) { this . value = null ; } this . innerValue = value ; } registerOnChange ( fn ) { this . changed . push ( fn ) ; } registerOnTouched ( fn ) { this . touched . push ( fn ) ; } }