Two way binding using radiobutton in Angular Radio button component

15 Sep 20223 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 { Component } from '@angular/core';

    selector: 'app-root',
    // To customize RadioButton appearance
    template: ` <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 class="dropDownList-control">
                    <h4>Payment Method</h4>
                    <ejs-dropdownlist [dataSource]='paymentMethod' [(value)]="value" ></ejs-dropdownlist>

export class AppComponent {
    public paymentMethod: string[] = ['Credit card', 'Debit card', 'Net Banking', 'Other Wallets' ];
    public value:string = "Credit card";
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 { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';
import { FormsModule } from '@angular/forms';

 * Module
    imports: [
    declarations: [AppComponent],
    bootstrap: [AppComponent]
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';