I have the following html code
<mat-tab label="Regular" (selectChange)="tabClick()"
(click)="tabClick()">
<h1>Some more tab content</h1>
</mat-tab>
and this is the function,
tabClick(){
console.log('Tab clicked...');
}
but it doesn't seems to be called, why? No one of the above events are fired?
The selectedTabChanged
event has to be attached to the <mat-tab-group>
element
<mat-tab-group (selectedTabChange)="tabClick($event)">
<mat-tab label="Tab 1">Content 1</mat-tab>
<mat-tab label="Tab 2">Content 2</mat-tab>
</mat-tab-group>
tabClick(tab) {
console.log(tab);
}
Demo
<mat-tab-group (selectedTabChange)="onChange($event)">
<mat-tab label="Tab 1">Content 1</mat-tab>
<mat-tab label="Tab 2">Content 2</mat-tab>
</mat-tab-group>
Selected tab will trigger out the tabChange Event and get the active tab.
And in the .ts
file:
onChange(event: MatTabChangeEvent) {
const tab = event.tab.textLabel;
console.log(tab);
if(tab===" Tab 1")
{
console.log("function want to implement");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With