如何实现 Angular Material mat-select 更改事件?

koq*_*que 3 angular-material

我想在 Angular Material 中实现以下引导选择。如何在引导程序中实现此处显示的更改事件?

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

如何将更改事件添加到调用 sortByProducts 函数的材料中,如上面所示的代码段中所做的那样?

<mat-form-field>
   <mat-select>
       <mat-option *ngFor="let filter of filters" [value]="filter.id">
            {{filter.title}}
       </mat-option>
   </mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

Ber*_*aga 8

您可以使用一个 selectionChange 输出:

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

// ts
sortByProducts(value) {
    console.log(value)
}
Run Code Online (Sandbox Code Playgroud)

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