Angular Material Selected Tab Change Event Example
This article will provide some of the most important example angular material tab change event example. This post will give you simple example of angular material mat tab change event. Here you will learn angular material mat-tab click event. We will use angular material tab select event.
I will show you simple example of angular material tab select change event 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.
So, let's see simple example.
Create New App
If you are doing example from scratch then You can easily create your angular app using bellow command:
ng new app-material
Add Material Design
Now in this step, we need to just install material design theme in our angular application. so let's add as like bellow:
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: https://material.angular.io?theme=indigo-pink ]
? Set up global Angular Material typography styles? Yes
? Set up browser animations for Angular Material? Yes
Basic Material Slider Toggle Button
Here, we will create very simple example. first we need to import MatTabsModule, and BrowserAnimationsModule for this example.
so let's update app.module.ts, app.component.ts and app.component.html.
Let's follow step:
src/app/app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import {MatTabsModule} from '@angular/material/tabs';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
imports: [ BrowserModule, FormsModule, MatTabsModule, BrowserAnimationsModule ],
declarations: [ AppComponent],
bootstrap: [ AppComponent ]
})
export class AppModule { }
src/app/app.component.html
<h1>Angular Material Tabs Example - ItSolutionStuff.com</h1>
<mat-tab-group (selectedTabChange)="onTabClick($event)">
<mat-tab label="Basic Setting">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</mat-tab>
<mat-tab label="SMS Setting">
<p>This is SMS Setting</p>
</mat-tab>
<mat-tab label="Email Setting">
<p>This is Email Setting</p>
</mat-tab>
</mat-tab-group>
src/app/app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent{
name = 'Angular';
onTabClick(event) {
console.log(event);
console.log(event.tab.textLabel);
}
}
You can easily run by following command:
ng serve
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Angular Material Tooltip Example
- Angular Material Checkbox Example
- Angular Material Slide Toggle Example
- Angular Material Textarea Tutorial
- Angular Material Radio Button Example
- Angular Material Input Box Example
- Angular Material Mat-Select with Reactive Form Example
- Angular Material Datepicker Example
- How to install material design in Angular 9/8?