Home Angular 10 Angular Material Nested Menu Working Tutorial

Angular Material Nested Menu Working Tutorial

by therichpost
Published: Last Updated on 5 comments
Angular Material Nested Menu Working Tutorial

Hello friends, welcome back to my blog. Today in this blog post, I am going to tell you, Angular Material Nested Menu Working Tutorial.

Angular Material Nested Menus

Angular 10 came and if you are new then you must check below two links:

  1. Angular10 for beginners
  2. Angular10 Basic Tutorials

Friends, here is the working code snippet for Angular Material Nested Menu Working Tutorial and please use it carefully to avoid mistakes:

1. Firstly friends we need fresh angular 10 setup and for this we need to run below commands but if you already have angular 10 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

npm install -g @angular/cli

ng new angularmaterial

cd angularmaterial

ng serve --o

//Here is the url, you need to run into your browser and see working angular test project


2. Now friends we need to run below command into our project terminal to get angular material and its related modules:

ng add @angular/material

ng serve --o


3. Now friends we need to add below code into our project/src/app/app.module.ts file to import the angular material table, angular material select input and its related modules:


//Import Angular Material Toolbar and its related modules like menu icon, buttons
import {MatToolbarModule} from '@angular/material/toolbar';

import {MatIconModule} from '@angular/material/icon';
import {MatButtonModule} from '@angular/material/button';
import {MatMenuModule} from '@angular/material/menu';

 imports: [


4. Finally friends we need to add below code into our project/src/app/app.component.html file to get the final output on web browser:

<mat-toolbar color="primary">
    <button mat-icon-button class="example-icon" aria-label="Example icon-button with menu icon">
    <button mat-button [matMenuTriggerFor]="animals">Nested Menus</button>
    <mat-menu #animals="matMenu">
      <button mat-menu-item [matMenuTriggerFor]="vertebrates">Vertebrates</button>
      <button mat-menu-item [matMenuTriggerFor]="invertebrates">Invertebrates</button>

    <mat-menu #vertebrates="matMenu">
      <button mat-menu-item [matMenuTriggerFor]="fish">Fishes</button>
      <button mat-menu-item [matMenuTriggerFor]="amphibians">Amphibians</button>
      <button mat-menu-item [matMenuTriggerFor]="reptiles">Reptiles</button>
      <button mat-menu-item>Birds</button>
      <button mat-menu-item>Mammals</button>

    <mat-menu #invertebrates="matMenu">
      <button mat-menu-item>Insects</button>
      <button mat-menu-item>Molluscs</button>
      <button mat-menu-item>Crustaceans</button>
      <button mat-menu-item>Corals</button>
      <button mat-menu-item>Arachnids</button>
      <button mat-menu-item>Velvet worms</button>
      <button mat-menu-item>Horseshoe crabs</button>

    <mat-menu #fish="matMenu">
      <button mat-menu-item>Baikal oilfish</button>
      <button mat-menu-item>Bala shark</button>
      <button mat-menu-item>Ballan wrasse</button>
      <button mat-menu-item>Bamboo shark</button>
      <button mat-menu-item>Banded killifish</button>

    <mat-menu #amphibians="matMenu">
      <button mat-menu-item>Sonoran desert toad</button>
      <button mat-menu-item>Western toad</button>
      <button mat-menu-item>Arroyo toad</button>
      <button mat-menu-item>Yosemite toad</button>

    <mat-menu #reptiles="matMenu">
      <button mat-menu-item>Banded Day Gecko</button>
      <button mat-menu-item>Banded Gila Monster</button>
      <button mat-menu-item>Black Tree Monitor</button>
      <button mat-menu-item>Blue Spiny Lizard</button>
      <button mat-menu-item disabled>Velociraptor</button>
    <button mat-button [matMenuTriggerFor]="menu">Menu</button>
    <mat-menu #menu="matMenu">
      <button mat-menu-item>Item 1</button>
      <button mat-menu-item>Item 2</button>
    <span class="example-spacer"></span>
    <button mat-icon-button class="example-icon favorite-icon" aria-label="Example icon-button with heart icon">
    <button mat-icon-button class="example-icon" aria-label="Example icon-button with share icon">


6. In the end friends for angular material table styling, we just need to add below code into our project/src/app/app.component.css file:

.example-spacer {
    flex: 1 1 auto;


Now we are done friends. If you have any kind of query or suggestion or requirement then feel free to comment below. Also friends click here to check more angular material working example.

Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.
I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.



You may also like


Bing Gelanga January 30, 2021 - 4:07 pm

I noticed that Step 4 is missing, I guess it is on “app.component.ts”.


Ajay Malhotra January 30, 2021 - 4:08 pm

Updated and thanks.

MarkF February 26, 2021 - 9:06 am

Good article, direct and to the point. And it work straight away!

Thanks for posting.

Ajay Malhotra February 26, 2021 - 9:49 am


sai shyan February 9, 2022 - 11:24 am

what is the condition for smaller devices


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.