Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement an Angular Material mat-select change event?

I want to implement the following bootstrap select in Angular Material. How do I implement the change event shown here in bootstrap?

<select (change)="sortByProducts($event.target.value)">
    <option *ngFor="let filter of filters" [value]="filter.id">
        {{filter.title}}
    </option>
</select>

How do I add the change event to material that calls the sortByProducts function as done in the code segment shown above?

<mat-form-field>
   <mat-select>
       <mat-option *ngFor="let filter of filters" [value]="filter.id">
            {{filter.title}}
       </mat-option>
   </mat-select>
</mat-form-field>
like image 276
koque Avatar asked Dec 14 '22 11:12

koque


1 Answers

There is a selectionChange output that you can use :

// html
<mat-select (selectionChange)="sortByProducts($event.value)">

// ts
sortByProducts(value) {
    console.log(value)
}

See https://material.angular.io/components/select/api

like image 73
Bernard Pagoaga Avatar answered Jun 20 '23 10:06

Bernard Pagoaga