You can follow these steps to achieve the desired outcome.
Step 1 :-
Start by installing Angular Material in your project using the following command npm install @angular/material
.
Step 2 :-
Include the following code snippet in the header of your index.html file.
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Step 3 :-
Import the required modules in your app.modules.ts or the root module file.
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatIconModule } from '@angular/material/icon';
Step 4 :-
Add the imported modules to the imports
array.
Step 5 :-
Insert the provided HTML code snippet into your HTML file.
<mat-sidenav-container class="example-container" *ngIf="shouldRun">
<mat-sidenav #sidenav mode="side" [(opened)]="opened" (opened)="events.push('open!')"
(closed)="events.push('close!')">
Sidenav content
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar color="primary">
<mat-toolbar-row>
<mat-icon aria-hidden="false" aria-label="Example home icon" (click)="sidenav.toggle()">menu</mat-icon>
<span>Custom Toolbar</span>
</mat-toolbar-row>
</mat-toolbar>
<p>Events:</p>
<div class="example-events">
<div *ngFor="let e of events">{{e}}</div>
</div>
</mat-sidenav-content>
</mat-sidenav-container>
Step 6 :-
Copy and paste the given TypeScript code into your TS file.
events: string[] = [];
opened: boolean;
shouldRun = [/(^|\.)plnkr\.co$/, /(^|\.)stackblitz\.io$/].some(h => h.test(window.location.host));
Step 7 :-
Apply the specified CSS styling in your component's SCSS file.
.example-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
Step 8 :-
Import the necessary theme in your style.scss file.
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
For a demonstration, please refer to this working demo
If you encounter any difficulties, feel free to reach out for assistance.