如何实现“角材料”垫选择更改事件?

时间:2019-05-06 15:08:24

标签: angular-material

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

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

如何按照上面显示的代码段所述,将change事件添加到调用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>

1 个答案:

答案 0 :(得分:2)

有一个selectionChange输出可以使用:

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

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

请参见https://material.angular.io/components/select/api