I am using Angular 2 (TypeScript).
How do you trigger a function, such as onChange(), whenever when I select a new option?
When I searched online, all I found was information about ng-change in Angular 1. (https://docs.angularjs.org/api/ng/directive/ngChange)
<select [(ng-model)]="selectedDevices">
<option *ng-for="#i of devices">{{i}}</option>
</select>
Thanks
Since angular2 ties directly into DOM events, you can just listen to the change event:
<select [(ng-model)]="selectedDevices" (change)="changeHandler($event)">
And then in your component:
public changeHandler($event) {
// do something here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With