Skip to content

Instantly share code, notes, and snippets.

@jcamilom
Created September 18, 2020 04:43
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 jcamilom/6df508d6a17f4e49d17e93b153e9a0c6 to your computer and use it in GitHub Desktop.
Save jcamilom/6df508d6a17f4e49d17e93b153e9a0c6 to your computer and use it in GitHub Desktop.
export class MultiCheckFieldComponent implements ControlValueAccessor {
_onChange: (_: any) => void;
registerOnChange(fn: any): void {
this._onChange = fn;
}
private add(value: any): void {
this.selectedValues.push(value);
this._onChange(this.selectedValues);
}
private remove(value: any): void {
const idx = this.selectedValues.findIndex(v => v === value);
if (idx >= 0) {
this.selectedValues.splice(idx, 1);
this._onChange(this.selectedValues);
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment