Skip to content

Instantly share code, notes, and snippets.

@jcamilom
Created September 18, 2020 04:22
Show Gist options
  • Save jcamilom/8c004c2a031da7d6eef316103d364d6c to your computer and use it in GitHub Desktop.
Save jcamilom/8c004c2a031da7d6eef316103d364d6c to your computer and use it in GitHub Desktop.
private subscriptions = new Subscription();
private selectedValues: any[] = [];
ngAfterContentInit(): void {
this.options.forEach(option => {
this.subscriptions.add(
option.valueChanges$.subscribe(
(optionChecked) => {
if (optionChecked) {
this.add(option.value);
} else {
this.remove(option.value);
}
}
)
);
});
}
private add(value: any): void {
this.selectedValues.push(value);
}
private remove(value: any): void {
const idx = this.selectedValues.findIndex(v => v === value);
if (idx >= 0) {
this.selectedValues.splice(idx, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment