我想在使用md-select选择值时在打字稿中调用函数。在材料设计中用于此目的的属性是什么?在md-select中选择Angular 4中的所选事件
<md-select placeholder="State">
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}
</md-option>
我想在使用md-select选择值时在打字稿中调用函数。在材料设计中用于此目的的属性是什么?在md-select中选择Angular 4中的所选事件
<md-select placeholder="State">
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}
</md-option>
使用(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>
链接working demo。
的文档是这些类的东西很开放:
https://material.angular.io/components/select/api
@Output()
change
Event emitted when the selected value has been changed by the user.
<md-select (change)="wasThatSoHard($event)"></md-select>
它不工作的家伙! –
真的很酷的解决方案。非常感谢@Faisal。 –
不客气。乐意效劳 :) – Faisal