Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire an event on close of multiselect dropdown in Angular material

How to fire an event on close of multiselect dropdown in angular material? This is my HTML template

                  <mat-select  multiple
                  (focusout)="triggerEvent($event)">
                    <mat-option *ngFor="let option of templateOptions"[value]="option">
                      {{option.name}}
                    </mat-option>
                  </mat-select>
                </mat-form-field>

As of now event is getting fired on every selection of options. I want it to be triggered when user has done selecting all the values and clicks outside. I have tried blur also but same result.

like image 837
Sumit Sinha Avatar asked Dec 22 '22 21:12

Sumit Sinha


2 Answers

<mat-select multiple (openedChange)="triggerEvent($event)">
    <mat-option *ngFor="let option of templateOptions"[value]="option">
        {{option.name}}
    </mat-option>
</mat-select>

Seems like you are looking for openedChange event emitter. Event emitted when the select panel has been toggled.

document

like image 70
J.C. Fong Avatar answered Dec 28 '22 10:12

J.C. Fong


in version of angular material that i use(7.1.1>) you can use closed event like this:

 <mat-select (closed)="method()">
 ...
 </mat-select>

see this example in stackblitz.

like image 40
amir azizkhani Avatar answered Dec 28 '22 10:12

amir azizkhani