I want to use an angular selection list, but additionally, I'd like the user to be able to add new items to the list. If he has already selected a few, this selection should not get lost.
Usually, I'd add a method in the component to add the element to the data list, and then recreate the MatSelectionList I am binding to the view. But then the current selection is lost.
I've tried variations of this in the component (beware, it's pseudo-code):
@ViewChild("items", { static: true }) items: ElementRef;
addItem(item: Item): void {
var selectionList = <MatSelectionList><unknown>this.items
// Hoped to find something like:
// selectionList.options.add(...):
// or recreate the source, and remembering the selection:
// let selected = selectionList.selectedOptions.selected.map(s => s.value);
// this.items = new MatSelectionList(this._originalItems.push(newItem))
// this.items.selectedOptions.setSelected(...)
}