Skip to content

Instantly share code, notes, and snippets.

@kagklis
Last active April 20, 2022 19:24
Show Gist options
  • Save kagklis/e22fb132d2d4004f08fb5949d70ca20c to your computer and use it in GitHub Desktop.
Save kagklis/e22fb132d2d4004f08fb5949d70ca20c to your computer and use it in GitHub Desktop.
@Component({
selector: 'app-selection-list',
templateUrl: './selection-list.component.html',
styleUrls: ['./selection-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class SelectionListComponent {
public selectedItems: SelectedItems = {};
@Input() items!: IdOwner[] | null;
@Output() selectionChanged = new EventEmitter<SelectedItems>();
@ContentChild('itemTemplate', { static: false })
itemTemplateRef!: TemplateRef<any>;
selectItem(item: IdOwner) {
if (Object.keys(this.selectedItems).includes(item.id.toString())) {
delete this.selectedItems[item.id];
} else {
this.selectedItems[item.id] = item;
}
this.selectionChanged.emit(this.selectedItems);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment