Created
September 18, 2020 04:22
-
-
Save jcamilom/8c004c2a031da7d6eef316103d364d6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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