Angular 9/8 Material Select Box Examples

Today, We want to share with you Angular 9/8 Material Select Box Examples.In this post we will show you Angular Material Select Box Example, hear for Angular 9/8 mat-select Reactive Form Example we will give you demo and example for implement.In this post, we will learn about angular mat-select with an example.

Angular 9/8 Material Select Box Examples

There are the Following The simple About Angular Select – Bootstrap 4 & Material Design Full Information With Example and source code.

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

Read Also:  PHP Array Tutorial With Examples - filter array

Material Select Dropdown with Reactive Form

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 {MatSelectModule} from '@angular/material/select';
import {MatButtonModule} from '@angular/material/button';
  
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    ReactiveFormsModule,
    MatSelectModule,
    MatButtonModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

src/app/app.component.html


<h1>Angular Material Select Box Example - pakainfo.com</h1>
    
<form [formGroup]="form" (ngSubmit)="submit()">
  <mat-form-field>
    <mat-label>Select Blogspot</mat-label>
    <mat-select formControlName="blogspot">
      <mat-option *ngFor="let blogspot of blogspots" [value]="blogspot.value">
        {{blogspot.viewValue}}
      </mat-option>
    </mat-select>
    <mat-error *ngIf="form.get('blogspot').hasError('required')">
        Please select blogspot
    </mat-error>
  </mat-form-field>
    
  <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';
  
interface Blogspot {
  value: string;
  viewValue: string;
}
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app-gretting';
  
  blogspots: Blogspot[] = [
    {value: '1', viewValue: 'pakainfo.com'},
    {value: '2', viewValue: 'ministackoverflow.com'},
    {value: '3', viewValue: 'infinityknow.com'}
  ];
  
  form: FormGroup = new FormGroup({});
  
  constructor(private fb: FormBuilder) {
  
    this.form = fb.group({
      blogspot: ['', [Validators.required]],
    })
  }
   
  get f(){
    return this.form.controls;
  }
    
  submit(){
    console.log(this.form.value);
  }
}

Web Programming Tutorials Example with Demo

Read :

Read Also:  Form Select Dropdown with Angular Material(mat-select)

Summary

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


I hope you get an idea about angular mat-select.
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.