使用Angular Material2 mat-selection-list,能够识别当前选项是选中还是未选中[布尔].
compnenent.html
<mat-selection-list #shoes (selectionChange)="onSelection($event, shoes.selectedOptions)" >
<mat-list-option *ngFor="let shoe of typesOfShoes" [value]='shoe'>
{{shoe}}
</mat-list-option>
</mat-selection-list>
Run Code Online (Sandbox Code Playgroud)
component.ts
export class ListSelectionExample {
typesOfShoes = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];
onSelection(e, v){
console.error(e.option.selected,v);
}
}
Run Code Online (Sandbox Code Playgroud)
e.option.selected 通知当前选项是选中还是未选中.
如何识别当前选定的值?尝试使用ngModel和ngModelChange的多个组合并单击,对我来说没有任何作用.
https://stackblitz.com/edit/angular-eyjdfp-qgjhvd?file=app%2Flist-selection-example.ts