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.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

Snippet Contents

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 :

Summary

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

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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   PHP Laravel 6 Form Validation Script
  2.   jQuery AJAX Submit form serialize PHP MySQLi
  3.   Form Radio Button with Angular Material(mat radio button)
  4.   Bind Array to Radio Button List using Angular Example
  5.   Export HTML Table Data to CSV using jQuery
  6.   Create JSON with json_encode and json_decode using PHP
  7.   How to bind the change event handler to radio button with Angular
  8.   Laravel Edit DropDown Option Seleted Example
  9.   Angular 9/8 Radio Button on Form Submit
  10.   laravel redirect new tab