AngularJS provides ngModel to bind values to input fields. Binding radio buttons to scope variables is tricky.
Markup
Here gender is the common variable which was bound to both radio button. On click of below buttons, gender value changes respectively.
<button (click)="gender = 'male'">Select Male</button> <button (click)="gender = 'female'" >Select Female</button> <input type="radio" [(ngModel)]="gender" value="male" name="gender"/> Male<br> <input type="radio" [(ngModel)]="gender" value="female" name="gender"/> Female<br>
Script - app.component.ts
Here we initiate only gender variable
export class AppComponent { gender: string = 'male'; }
Script - app.module.ts
In order to use ngModel, we should import FormsModule into our app module
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { FormsModule } from '@angular/forms'; @NgModule({ imports: [ BrowserModule, FormsModule ], declarations: [ AppComponent], bootstrap: [ AppComponent ] }) export class AppModule { }
This blog really inspired me a lot
ReplyDeleteadult services local girls
Great Article
DeleteFinal Year Projects for CSE in Angular
Angular Training in Chennai
Project Centers in Chennai
JavaScript Training in Chennai
how to reset radio button on click in angular 6
ReplyDeleteEven though laminate floors give the looks of hardwood floors, they do not contain wood at all. They are made of various materials bonded together under high pressure which makes it highly durable, and the high-density fiberboard layer makes it moisture resistant. You can contact our flooring contractors in Jacksonville FL to assist you with installing different types of floors.
ReplyDelete