Why doesn't nGOnChanges start when you "writeValue" in ControlValueAccessor? I emit some events through registerOnChange, but I don't see any action in ngOnChanges
const CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR = new Provider( NG_VALUE_ACCESSOR, { useExisting: forwardRef(() => CustomInput), multi: true }); @Component({ moduleId: module.id, selector: 'custom-input', templateUrl: 'custom-input.html', styleUrls: ['custom-input.css'], directives: [CORE_DIRECTIVES], providers: [CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR] }) export class CustomInput implements ControlValueAccessor{ private _text: any = ''; public isValid:boolean = false; onChange: EventEmitter<any> = new EventEmitter(); onTouched: any; constructor(private ngControl:NgControl) { } ngOnChanges(e) { console.log('ngOnChanges'); } get text(): any { return this._text; }; set text(v: any) { if (v !== this._text) { this._text = v; this.onChange.emit(v); } } writeValue(v) { this.text = v; } registerOnChange(fn): void { this.onChange.subscribe(fn); } registerOnTouched(fn): void { this.onTouched = fn; } }
source share