Skip to content

Instantly share code, notes, and snippets.

@afirdousi
Created July 3, 2017 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afirdousi/72599674dbe9078e8295cf9bed8b1e59 to your computer and use it in GitHub Desktop.
Save afirdousi/72599674dbe9078e8295cf9bed8b1e59 to your computer and use it in GitHub Desktop.
export abstract class AbstractValueAccessor<T> implements ControlValueAccessor {
_value: T = '';
get value(): T { return this._value; };
set value(v: T) {
if (v !== this._value) {
this._value = v;
this.onChange(v);
}
}
writeValue(value: T) {
console.log('wrrite value', value);
this._value = value;
this.onChange(value);
}
onChange = (_) => {};
onTouched = () => {};
registerOnChange(fn: (_: any) => void): void { this.onChange = fn; }
registerOnTouched(fn: () => void): void { this.onTouched = fn; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment