<mat-menu> in Angular Material
Angular Material is a UI component library that is developed by the Angular team to build design components for desktop and mobile web applications. In order to install it, we need to have angular installed in our project, once you have it you can enter the below command and can download it.
The <mat-menu> acts as a kind of dropdown or menu section which expands or opens whenever user clicks on any button.
ng add @angular/material
- First, install the angular material using the above-mentioned command.
- After completing the installation, Import ‘MatMenuModule’ from ‘@angular/material/menu’ in the app.module.ts file.
- In addition to it import ‘MatButtonModule’ from ‘@angular/material/button’ in app.module.ts file.
- Then use <mat-menu> tag to group all the items inside this menu tag.
- Inside the <mat-menu> tag we need to use <mat-menu-item> tag for every item for displaying in the dropdown.
- We have properties like ‘xPosition’ and ‘yPosition’ to customize the opening direction of the dropdown.
- Once done with the above steps then serve or start the project.