[英]Angular material multi select get selected value on hide
Scenario:设想:
Todo:去做:
I want to get the selected values on hide of dropdown..我想在隐藏的下拉列表中获取选定的值..
I googled and tried to find the doc but could not found any ref to add hide event to miltiselect
我用谷歌搜索并试图找到文档,但找不到任何参考来将隐藏事件添加到 miltiselect
Demo where multi-select values are available after closed mat-select dropdown 在关闭mat-select下拉列表后可以使用多选值的演示
Application Code : https://stackblitz.com/edit/angular-values-access-after-dropdown-close?file=src/app/app.component.html 应用代码: https : //stackblitz.com/edit/angular-values-access-after-dropdown-close?file = src / app / app.component.html
Approach : 方法:
multi-select
values. multi-select
值。 openedChange
event as (openedChange)="comboChange($event)"
, and in that store the selected values into an array or a different variable. openedChange
事件作为(openedChange)="comboChange($event)"
,并在该存储中将选定的值存储到数组或不同的变量中。 false
if dropdown is closed, so i have used it in the demo code. false
,因此我在演示代码中使用了它。 mat-select
is used with [formControl]="toppings"
, so in any other method, you can access its value using this.toppings.value
, it will return an array with selected values. mat-select
与[formControl]="toppings"
,因此在任何其他方法中,您可以使用this.toppings.value
访问其值,它将返回一个包含所选值的数组。 Adding Formcontrol variable like below we can enumerate the selected items from a angular multiselect dropdown添加如下 Formcontrol 变量,我们可以从 angular 多选下拉列表中枚举所选项目
<mat-select multiple placeholder="Reason" [formControl]="selectedReasons">
<mat-option value="option1">option1</mat-option>
<mat-option value="option2">option2</mat-option>
<mat-option value="option3">option3</mat-option>
<mat-option value="option4">option4</mat-option>
</mat-select>
TS TS
selectedReasons = new FormControl();
reasonDropdownChangeEvent(event: any) {
console.log(this.selectedReasons.value.toString());
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.