1. Material Setup
Install Angular Material using Angular CLI:
- Select a theme (prebuilt or custom)
- Enable global typography
- Enable animations (recommended)
Import BrowserAnimationsModule in AppModule:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
imports: [BrowserAnimationsModule]
})
export class AppModule { }
2. Material Components
2.1 Buttons
Angular Material provides styled buttons:
<button mat-button>Basic</button>
<button mat-raised-button color="primary">Primary</button>
<button mat-icon-button>
<mat-icon>favorite</mat-icon>
</button>
2.2 Forms
Use Material form fields for input elements:
<mat-form-field appearance="fill">
<mat-label>Username</mat-label>
<input matInput placeholder="Enter username">
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Email</mat-label>
<input matInput placeholder="Enter email">
</mat-form-field>
- Also includes checkboxes, radio buttons, sliders, and select dropdowns
2.3 Navigation
Material provides navigation components:
<mat-toolbar color="primary">My App</mat-toolbar>
<mat-sidenav-container>
<mat-sidenav mode="side" opened>Side Menu</mat-sidenav>
<mat-sidenav-content>Main Content</mat-sidenav-content>
</mat-sidenav-container>
<mat-tab-group>
<mat-tab label="Home">Home Content</mat-tab>
<mat-tab label="About">About Content</mat-tab>
</mat-tab-group>
2.4 Dialogs
Open modal dialogs easily:
import { MatDialog } from '@angular/material/dialog';
import { DialogComponent } from './dialog/dialog.component';
constructor(private dialog: MatDialog) {}
openDialog() {
this.dialog.open(DialogComponent, {
width: '300px',
data: { name: 'Chinmaya' }
});
}
2.5 Tables
Material tables support sorting, pagination, and filtering:
<table mat-table [dataSource]="dataSource">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Name</th>
<td mat-cell *matCellDef="let element">{{element.name}}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
2.6 Snackbar
Display temporary messages:
import { MatSnackBar } from '@angular/material/snack-bar';
constructor(private snackBar: MatSnackBar) {}
showMessage() {
this.snackBar.open('Data saved successfully!', 'Close', {
duration: 3000
});
}
3. Themes & Custom Theming
Angular Material supports theming for a consistent look:
@use '@angular/material' as mat;
$my-primary: mat.define-palette(mat.$indigo-palette);
$my-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
$my-theme: mat.define-light-theme((
color: (
primary: $my-primary,
accent: $my-accent
)
));
@include mat.all-component-themes($my-theme);
- Choose prebuilt themes (
indigo-pink, deeppurple-amber, pink-bluegrey) - Create custom themes using SCSS for branding
Summary
- Install Angular Material using
ng add @angular/material. - Material provides ready-made UI components: Buttons, Forms, Navigation, Dialogs, Tables, Snackbar.
- Use mat-toolbar, mat-sidenav, mat-tab-group for navigation and layout.
- Snackbar and dialogs improve user interaction.
- Material supports prebuilt and custom themes for consistent app styling.