Angular 9/8 Material Radio Button Examples

Today, We want to share with you Angular 9/8 Material Radio Button Examples.In this post we will show you Angular 8/9 Radio Buttons Tutorial with Examples, hear for angular material radio-button default selected we will give you demo and example for implement.In this post, we will learn about Material Radio Button with Reactive Form with an example.

Angular 9/8 Material Radio Button Examples

There are the Following The simple About mat-radio-group formcontrolname Full Information With Example and source code.

As I will cover this Post with live Working example to develop angular material radio-button example, so the mat-radio-button change event is used for this example is following below.

Angular Material Radio Button Example

src/app/app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
  
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
  
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import {MatRadioModule} from '@angular/material/radio';
import {MatButtonModule} from '@angular/material/button';
  
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    ReactiveFormsModule,
    MatRadioModule,
    MatButtonModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

src/app/app.component.html

<h1>Angular Material Radio Button Example - pakainfo.com</h1>
   
<form [formGroup]="form" (ngSubmit)="submit()">
  
  <mat-radio-group
    aria-labelledby="example-radio-group-label"
    class="example-radio-group"
    formControlName="foodField">
    <mat-radio-button class="example-radio-button" *ngFor="let food of foods" [value]="food">
      {{food}}
    </mat-radio-button>
  </mat-radio-group>
  <div *ngIf="form.get('foodField').hasError('required')" class="error">
        Food is required
  </div>
    
  <button mat-raised-button color="purple">Submit</button>
</form>

src/app/app.component.ts

import { Component } from '@angular/core';
  
import { FormBuilder, FormGroup, Validators} from '@angular/forms';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app-gretting';
  
  foods: string[] = ['Banana', 'Apple', 'Mango'];
  form: FormGroup = new FormGroup({});
  
  constructor(private fb: FormBuilder) {
  
    this.form = fb.group({
      foodField: ['', [Validators.required]],
    })
  }
    
  get f(){
    return this.form.controls;
  }
    
  submit(){
    console.log(this.form.value);
  }
}

Web Programming Tutorials Example with Demo

Read :

Read Also:  Login with Facebook and Twitter

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Free Live Chat for Any Issue
Download

I hope you get an idea about angular 6 radio button example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.