Angular Material Select Option Group Example

By Hardik Savani May 2, 2024 Category : Angular


This tutorial is focused on angular material select option group. this example will help you angular material select group. i explained simply about angular material mat select group. i explained simply step by step angular material select multiple group.

We can create material select dropdown with option group in angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17.

Here i will give you very simple example of how to add group of option using angular material select box. so let's see bellow full example:

You can see bellow layout for demo:

Step 1: Create New App

This step is not required; however, if you have not created the angular app, then you may go ahead and execute the below command:

ng new app-material

Step 2: Add Material Design

Now you have to install the material library in angular app. So, we can use angular material components:

ng add @angular/material

Cmd like bellow:

Installing packages for tooling via npm.

Installed packages for tooling via npm.

? Choose a prebuilt theme name, or "custom" for a custom theme: Indigo/Pink

[ Preview: ]

? Set up global Angular Material typography styles? Yes

? Set up browser animations for Angular Material? Yes

Step 3: Import Module

first we need to import MatFormFieldModule and MatSelectModule. so let's update app.module.ts.

Let's follow step:


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';


declarations: [



imports: [








providers: [],

bootstrap: [AppComponent]


export class AppModule { }

Step 4: Update Template File

Here, you have to update html template file as bellow:


<h1>Angular Material Select Box with Group Example -</h1>

<form [formGroup]="form" (ngSubmit)="submit()">


<mat-label>Select Website</mat-label>

<mat-select formControlName="website">

<mat-option>-- None --</mat-option>

<mat-optgroup *ngFor="let websiteList of websitesGroup" [label]=""


<mat-option *ngFor="let website of websiteList.list" [value]="website.value">





<mat-error *ngIf="form.get('website')?.hasError('required')">

Please select website



<button mat-raised-button color="accent">Submit</button>


Step 5: Update Ts File

Here, you have to update ts file as bellow:


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

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

interface Website {

value: string;

viewValue: string;


interface WebsiteGroup {

disabled?: boolean;

name: string;

list: Website[];



selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']


export class AppComponent{

title = 'app-material3';

selectedOption = ['2','3'];

websitesGroup: WebsiteGroup[] = [


name: 'Blog',

list: [

{value: '1', viewValue: ''},

{value: '2', viewValue: ''},

{value: '3', viewValue: ''},




name: 'Language',

list: [

{value: '4', viewValue: ''},

{value: '5', viewValue: ''},




form: FormGroup = new FormGroup({});

constructor(private fb: FormBuilder) {

this.form ={

website: [this.selectedOption, [Validators.required]],



get f(){

return this.form.controls;






Run Angular App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Angular app:

ng serve

Now, Go to your web browser, type the given URL and view the app output:


I hope it can help you...