Angular Radio Buttons Demo with Reactive Forms

In this tutorial, we will create a reactive form in Angular which contains radio buttons as its form controls.

For demonstration purposes, we have created a form group named userForm which contains three form controls firstName, lastName and gender.

The firstName and lastName fields are simple text fields, whereas the gender field is a radio button.

To show the options of the radio buttons dynamically, we have defined a genders array in our ts file which contains the value and title of each option of the radio button.

Have a look at our ts file:

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
export class AppComponent implements OnInit {

  genders: any[] = [
    { value: 'Male', title: 'Male' },
    { value: 'Female', title: 'Female' },
    { value: 'Others', title: 'Others' },

  userForm: FormGroup;
  isFormSubmitted: boolean = false;;

  constructor(private fb: FormBuilder) {

    this.userForm ={
      'firstName': ['', Validators.required],
      'lastName': ['', Validators.required],
      'gender': ['', Validators.required]


  ngOnInit(): void {


    // Get the value of the form
    this.formData = this.userForm.value;

    // To show form data in template(just for demo)
    this.isFormSubmitted = true;

    // Add your stuff

…And here is our template file:

 <div class="container">

  <form [formGroup]="userForm">
      <input type="text" formControlName="firstName" placeholder="Type here">
      <label> First Name</label>
      <input type="text" formControlName="lastName" placeholder="Type here">
      <label> Last Name</label>

      <span>Select Gender</span><br>
      <div *ngFor="let gender of genders">
        <input type="radio" name="gender" [value]="gender.value" formControlName="gender">

    <button type="submit" (click)="submit()" [disabled]="userForm.invalid">Submit</button>

    <!-- Show form data on submission(just for demonstration) -->
    <p *ngIf="isFormSubmitted">Form Data: {{formData | json}}</p>



Angular Radio Buttons Demo with Reactive Forms

Please note that the submit button remains disabled until the user fills/selects all the mandatory fields.

That’s because we have bind the disabled property of the button with the invalid property of the reactive form.

The invalid property returns true if the form is invalid and returns false if the form is valid.

That’s all for this article. Thanks for reading!


  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.