I have a tree with a selection of items. I organized the picklist change event like this.
checklistSelection = new SelectionModel<TodoItemFlatNode>(true);
this.checklistSelection.changed.subscribe(data => {
this.selectedEmit.emit(this.checklistSelection.selected.map(s => s.item));
});
Previously, the user could only select tree elements by clicking. And everything was fine. I have now added a "select all" button.
public SelectAllNode(): void {
this.checklistSelection.clear();
if (this.isCheckedAllNode) {
for (let dataNode of this.treeControl.dataNodes) {
this.checklistSelection.select(dataNode);
}
} else {
for (let dataNode of this.treeControl.dataNodes) {
this.checklistSelection.deselect(dataNode);
}
}
}
I have over 3000 items in my tree. When the user clicks this button, 3000 events happen - very impractical. Please tell me how best to organize the selection of all elements? For example, unsubscribe from an event, and at the end subscribe to it again?
It seems that the problem went away when I did this:
But I don't know how good this is.