how can I select a specific tab when an event occur?
I tried with [selectedIndex]="selectedTab"
changing the selectedTab
to the tab index needed but it doesn't seems to work after the tabs are loaded...
how can I select a specific tab when an event occur?
I tried with [selectedIndex]="selectedTab"
changing the selectedTab
to the tab index needed but it doesn't seems to work after the tabs are loaded...
I had the same issue and I tried the above answers but they are not helping. Here is my solution:
In my typescript code, first, declare a variable:
then, in the function:
in the html,
In case it helps anyone, it is also possible to set
selectedIndex
on the MatTabGroup in your component.If your HTML has:
<mat-tab-group #tabs>
, you can get a reference to it in the component using@ViewChild('tabs') tabGroup: MatTabGroup;
.Then you can do
this.tabGroup.selectedIndex = newIndex;
in the OnInit function, or elsewhere.Should work, maybe anywhere else a problem? Any error message?
live-demo: http://plnkr.co/edit/k2cw7Jw5YEstrY3OWbdq?p=preview