Name and value in form submit in Angular Radio button component

14 Nov 20223 minutes to read

The name attribute of the RadioButton is used to group RadioButton. When the RadioButton are grouped in form, the checked item value attribute will be post to server on form submit
that can be retrieved through the name. The disabled and unchecked RadioButton value will not be sent to the server on form submit.

In the following code snippet, Credit and Debit card is in the checked state. Now, the value that is in checked state will be sent on form submit.

import { Component } from '@angular/core';
import { NgForm } from '@angular/forms';

    selector: 'app-root',
    // Name and Value attribute in form submit.
    template: `<form #form="ngForm" (ngSubmit)="submitForm(form)">
                    <li><ejs-radiobutton name="payment" [(ngModel)]="selectedOption" value="credit/debit" label="Credit / Debit card" checked="true"></ejs-radiobutton></li>

                    <li><ejs-radiobutton name="payment" [(ngModel)]="selectedOption" value="netbanking" label="Net Banking"></ejs-radiobutton></li>

                    <li><ejs-radiobutton name="payment" [(ngModel)]="selectedOption" value="cashondelivery" label="Cask On Delivery"></ejs-radiobutton></li>

                    <li><ejs-radiobutton name="payment" [(ngModel)]="selectedOption" value="others" label="Others"></ejs-radiobutton></li>

                    <li><button ejs-button [isPrimary]="true">Submit</button></li>

export class AppComponent {
    public selectedOption: string = 'credit/debit';
    submitForm(form: NgForm): void  {
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule, RadioButtonModule } from '@syncfusion/ej2-angular-buttons';
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';