对于材质版本 >= 6
Use the (selectionChange)
事件于mat-select
.
<mat-form-field>
<mat-select placeholder="State" (selectionChange)="someMethod($event.value)">
<mat-option *ngFor="let state of states" [value]="state.value">
{{ state.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
在事件方法中,$event.value
包含当前选择的[value]
。参考官方文档 https://material.angular.io/components/select/api.
@Output() SelectionChange: EventEmitter
当用户更改所选值时发出事件。
这是一个链接Stackblitz 演示 https://stackblitz.com/edit/angular-6-stackoverflow-9wpyd8?file=src%2Fapp%2Fcomponents%2Fstackoverflow-solution%2Fstackoverflow-solution.component.html.
对于材质版本
Use the (change)
输出事件。
<md-select placeholder="State" (change)="someMethod()">
<md-option *ngFor="let state of states" [value]="state.value">
{{ state.viewValue }}
</md-option>
</md-select>
另一种方法是使用(onSelectionChange)
事件于<md-option>
:
<md-select placeholder="State">
<md-option *ngFor="let state of states" [value]="state.code"
(onSelectionChange)="anotherMethod($event, state)">
{{ state.name }}
</md-option>
</md-select>
Link to Stackblitz 演示 https://stackblitz.com/edit/angular-kzhjqm?file=app%2Fapp.component.html.