Last active
January 5, 2018 09:46
-
-
Save kevinchisholm/77df68d001537beaf0427189fe1dbfb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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