{{ item.name }}
onSelectionChange(event: MatSelectionListChange) {
event.options.forEach((option: MatListOption) => {
const item = option.value;
item.selected = option.selected;
});
}
this.items.forEach((item) => {
if (item.name === 'Item 1' || item.name === 'Item 3') {
item.selected = true;
}
});
这样,在模板中使用[selected]绑定的项目也将被正确选中。