showing results for - "angular material open last visited tab"
Andrés
19 Mar 2020
1constructor(private route: ActivatedRoute,
2  private router: Router) {}
3
4selectedTabIndex: number;
5
6ngOnInit(): void {
7  this.selectedTabIndex = parseInt(this.route.snapshot.queryParamMap.get('tab'), 10);
8  // TODO: check upper bound. Material will set the last tab as selected
9  // if selectedTabIndex >= number of tabs
10  if (isNaN(this.selectedTabIndex) || this.selectedTabIndex < 0) {
11    this.selectedTabIndex = 0;
12  }
13}
14
15onTabChange(selectedTabIndex: number): void {
16  this.router.navigate([], { relativeTo: this.route, queryParams: {
17    tab: selectedTabIndex
18  }});
19  this.selectedTabIndex = selectedTabIndex;
20}
21