1 import { Component, OnChanges } from '@angular/core';
2 import { Input } from '@angular/core';
5 selector: 'cd-select-badges',
6 templateUrl: './select-badges.component.html',
7 styleUrls: ['./select-badges.component.scss']
9 export class SelectBadgesComponent implements OnChanges {
10 @Input() data: Array<string> = [];
11 @Input() options: Array<SelectBadgesOption> = [];
12 @Input() emptyMessage = 'There are no items.';
17 if (!this.options || !this.data || this.data.length === 0) {
20 this.options.forEach((option) => {
21 if (this.data.indexOf(option.name) !== -1) {
22 option.selected = true;
27 private updateOptions() {
28 this.data.splice(0, this.data.length);
29 this.options.forEach((option: SelectBadgesOption) => {
30 if (option.selected) {
31 this.data.push(option.name);
36 selectOption(option: SelectBadgesOption) {
37 option.selected = !option.selected;
41 removeItem(item: string) {
42 const optionToRemove = this.options.find((option: SelectBadgesOption) => {
43 return option.name === item;
45 optionToRemove.selected = false;