我正在尝试实现角度MatSelectionList
并尝试使用API selectionChange侦听选定的选项事件,但它不会触发任何事件。
https://stackblitz.com/edit/angular-eyjdfp?file=app%2Flist-selection-example.html
我做错了什么或者在释放到角度6时发生了什么事情?
使用: Angular 6.0.1版本
Chrome浏览器
答案 0 :(得分:8)
组件行为在@ angular / material的6.0.0-beta.5中发生了变化:
list:MatListOption上的selectionChange,已弃用 5.0.0已被删除。请改用MatSelectionList上的selectionChange。
您需要在selectionChange
上应用mat-selection-list
,如下所示:
<mat-selection-list (selectionChange)="onSelection($event)" #shoes>
<mat-list-option *ngFor="let shoe of typesOfShoes" >
{{shoe}}
</mat-list-option>
</mat-selection-list>