Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinchisholm/24867592eb12c8cc49202daa1329907a to your computer and use it in GitHub Desktop.
Save kevinchisholm/24867592eb12c8cc49202daa1329907a to your computer and use it in GitHub Desktop.
import {Component} from '@angular/core';
@Component({
selector: 'home',
templateUrl: 'src/home/home.html',
styleUrls: ['src/home/home.css']
})
export class HomeComponent {
selectedDay: string = '';
//event handler for the select element's change event
selectChangeHandler (event: any) {
//update the ui
this.selectedDay = event.target.value;
}
}
<article>
<h1>Angular Get Selected Option Value</h1>
<h2><span>Select a day:</span></h2>
<select (change)="selectChangeHandler($event)">
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
</select>
<p><span>You selected: </span><b>{{selectedDay}}</b></p>
</article>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment