Last active
April 20, 2022 19:24
-
-
Save kagklis/e22fb132d2d4004f08fb5949d70ca20c 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
@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