How can I select a specific tab when an event occurs?
I tried with [selectedIndex]=\"selectedTab\" changing the selectedTab to the tab ind
I also had similar issue. In my case I needed to show the tab the user was there before he left the component. I solved this by stuffing the current selected tab index in a service.
On HTML template I have this:
Implementation of onTabChange and getSelectedIndex are as follows:
getSelectedIndex(): number {
return this.appService.currentTabIndex
}
onTabChange(event: MatTabChangeEvent) {
this.appService.currentTabIndex = event.index
}
My service code looks like this:
export class AppService {
public currentTabIndex = 1 //default tab index is 1
}