selectionChange属性不是在角类组件中触发事件

时间:2018-05-16 06:29:42

标签: angular angular-material2 angular6

我正在尝试实现角度MatSelectionList并尝试使用API​​ selectionChange侦听选定的选项事件,但它不会触发任何事件。

https://stackblitz.com/edit/angular-eyjdfp?file=app%2Flist-selection-example.html

我做错了什么或者在释放到角度6时发生了什么事情?

使用: Angular 6.0.1版本

Chrome浏览器

1 个答案:

答案 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>

Here is an edit of your stackblitz.