Having trouble getting help?
Contact Support
Contact Support
Two way binding using radiobutton in Angular Radio button component
27 Apr 20243 minutes to read
In the following example, two-way binding for RadioButton is illustrated with DropDownList component. The steps to achieve two-way binding in RadioButton are as follows,
-
Initialize RadioButton component and bind the checked value using ngModel as in the below code using “banana in a box” syntax,
<ejs-radiobutton [label]='payment' [value]="payment" name="payment" [(ngModel)]="value"></ejs-radiobutton>
-
Initialize DropDownList component and assign the
value
property value like the below code,<ejs-dropdownlist [dataSource]='paymentMethod' [(value)]="value" ></ejs-dropdownlist>
-
Now, the changes made in RadioButton will reflect in DropDownList (i.e. Selected option in radio button will be reflected in DropDownList ) and vice versa.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { RadioButtonModule } from '@syncfusion/ej2-angular-buttons'
import { DropDownListModule } from '@syncfusion/ej2-angular-dropdowns'
import { enableRipple } from '@syncfusion/ej2-base'
import { FormsModule } from '@angular/forms'
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
@Component({
imports: [
CommonModule,
RadioButtonModule,
FormsModule,
DropDownListModule
],
standalone: true,
selector: 'app-root',
// To customize RadioButton appearance
template: ` <div class="e-section-control">
<div class="radioButton-control">
<h4>Select a payment method</h4>
<div class="row" *ngFor='let payment of paymentMethod'>
<ejs-radiobutton [label]='payment' [value]="payment" name="payment" [(ngModel)]="value"></ejs-radiobutton>
</div>
</div>
<div class="dropDownList-control">
<h4>Payment Method</h4>
<ejs-dropdownlist [dataSource]='paymentMethod' [(value)]="value"></ejs-dropdownlist>
</div>
</div>`
})
export class AppComponent {
public paymentMethod: string[] = ['Credit card', 'Debit card', 'Net Banking', 'Other Wallets'];
public value:string = "Credit card";
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));