get current tab matedialtabs code example
Example: angular material open last visited tab
constructor(private route: ActivatedRoute,
private router: Router) {}
selectedTabIndex: number;
ngOnInit(): void {
this.selectedTabIndex = parseInt(this.route.snapshot.queryParamMap.get('tab'), 10);
if (isNaN(this.selectedTabIndex) || this.selectedTabIndex < 0) {
this.selectedTabIndex = 0;
}
}
onTabChange(selectedTabIndex: number): void {
this.router.navigate([], { relativeTo: this.route, queryParams: {
tab: selectedTabIndex
}});
this.selectedTabIndex = selectedTabIndex;
}