📅  最后修改于: 2022-03-11 15:03:36.052000             🧑  作者: Mango
constructor(private route: ActivatedRoute,
private router: Router) {}
selectedTabIndex: number;
ngOnInit(): void {
this.selectedTabIndex = parseInt(this.route.snapshot.queryParamMap.get('tab'), 10);
// TODO: check upper bound. Material will set the last tab as selected
// if selectedTabIndex >= number of tabs
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;
}