我想在使用md select Select 值时调用typescript中的函数.material 设计中用于此目的的属性是什么?
<md-select placeholder="State">
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}
</md-option>
我想在使用md select Select 值时调用typescript中的函数.material 设计中用于此目的的属性是什么?
<md-select placeholder="State">
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}
</md-option>
For Material version >= 6
使用101上的100事件.
<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>
在事件方法中,101包含当前 Select 的102.参考official documentation.
@Output() selectionChange: EventEmitter< MatSelectChange >
用户更改选定值时发出的事件.
这里是Stackblitz Demo的链接.
For Material version < 6
使用(change)
输出事件.
<md-select placeholder="State" (change)="someMethod()">
<md-option *ngFor="let state of states" [value]="state.value">
{{ state.viewValue }}
</md-option>
</md-select>
另一种方法是在<md-option>
上使用(onSelectionChange)
事件:
<md-select placeholder="State">
<md-option *ngFor="let state of states" [value]="state.code"
(onSelectionChange)="anotherMethod($event, state)">
{{ state.name }}
</md-option>
</md-select>
链接到Stackblitz Demo.