here is the code for radio button by default selection.
Ts
<h2>{{radioTitle}}</h2>
<label *ngFor="let radiobutton of radioItems">
<input type="radio" name="options" (click)="model.option = radiobutton"
[checked]="radiobutton === model.option">{{radiobutton}}
</label>
<p>
<button (click)="model.option = '12345'">
Set option #1
</button>
</p>
<p>
Selected option: {{model.option}}
</p>
Html
export class AppComponent {
radioTitle: string;
radioItems: Array<string>;
model = {option: '12347'};
constructor() {
this.radioTitle = 'Radio Button in Angular';
this.radioItems = ['12345', '12346', '12347'];
}
}
No comments:
Post a Comment