You need to use an Angular form directive on the select
. You can do that with ngModel
. For example
@Component({
selector: 'my-app',
template: `
<h2>Select demo</h2>
<select [(ngModel)]="selectedCity" (ngModelChange)="onChange($event)" >
<option *ngFor="let c of cities" [ngValue]="c"> {{c.name}} </option>
</select>
`
})
class App {
cities = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'Buffalo'}];
selectedCity = this.cities[1];
onChange(city) {
alert(city.name);
}
}
The (ngModelChange)
event listener emits events when the selected value changes. This is where you can hookup your callback.
Note you will need to make sure you have imported the FormsModule
into the application.
Here is a Plunker