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/77df68d001537beaf0427189fe1dbfb7 to your computer and use it in GitHub Desktop.
Save kevinchisholm/77df68d001537beaf0427189fe1dbfb7 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 = '';
days: any = [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday'
];
//event handler for the radio button's change event
radioChangeHandler (event: any) {
//update the ui
this.selectedDay = event.target.value;
}
}
<article>
<h1>Angular Get Radio Button Selected Value</h1>
<h2><span>Select a day:</span></h2>
<!-- for each day in the days array -->
<div *ngFor="let day of days">
<!-- create a radio button-->
<input
type="radio"
name="dayOfTheWeek"
value="{{day}}"
(change)="radioChangeHandler($event)">
<i>{{day}}</i>
</div>
<!-- the radio button change will be reflected below -->
<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