Angular Mat Select Multiple selectionchange 查找更改的选项 [英] Angular Mat Select Multiple selectionchange finding which option was changed

查看:37
本文介绍了Angular Mat Select Multiple selectionchange 查找更改的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 multiple 选项集(一个多选).当 selectionChange 事件触发时,我需要知道哪个选项已被选中或未选中,但是,它只返回所选选项的新当前列表.

I have a <mat select> with the multiple option set (a multi-select). When the selectionChange event fires I need to know which option has been checked or unchecked, however, it only returns the new current list of selected options.

例如我有一个列表:

<mat-select (selectionChange)="change($event)" multiple placeholder="Select">
  <mat-option value="1">one</mat-option>
  <mat-option value="2">two</mat-option>
  <mat-option value="3">three</mat-option>
  <mat-option value="4">four</mat-option>
</mat-select>

如果选项onethreefour被选中,然后用户未选中选项four,则在事件处理程序 我需要知道哪个选项触发了事件(即选项 four)及其新状态.我目前看不到在 selectionChange 事件中访问该信息的方法.

If options one, three and four are checked and then the user unchecked option four, in the event handler I need to know which option triggered the event (i.e. option four) and its new state. I currently don't see a way of accessing that information in the selectionChange event.

https://stackblitz.com/edit/angular-1e9gsd?file=app/select-overview-example.ts

我尝试将事件处理程序 (selectionChange)="change($event)" 放在 上,但似乎不是支持.

I tried putting the event handler (selectionChange)="change($event)" on the <mat-option> but it doesn't seem to be supported.

推荐答案

我需要在 上使用 onSelectionChange,它不同于selectionChange 可以在

I needed to use onSelectionChange on the <mat-option>, which is different than the selectionChange that you can use on the <mat-select>

如果 mat-select 的文档中有这样的内容就好了.

It would be nice if that was in the documentation for mat-select.

这里正在运行 https://stackblitz.com/edit/angular-1e9gsd-34hrwg?file=app/select-overview-example.html

这篇关于Angular Mat Select Multiple selectionchange 查找更改的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆