Is there any way to set default active tab by using labels or getting the index for that label before loading (active tab once the mat tab group initialise)
another thing i’m using ngIf for the container that holds the tabs so couldnt use view child to get the indexes or couldnt successfully set selectedIndex before loading the tabs
an example:
selectedTabTitle: string = '';
selectedTabIndex: number;
@ViewChild('tabsgroup ',{static: false})
set tabgroupp(tabgroup: MatTabGroup) {
if(tabgroup)
this.tabsgroup = tabgroup
setTimeout(() => {
this.selectedTabIndex=tabgroup._tabs["_results"].find(t=>t.textLabel== this.selectedTabTitle).position;
}, 0);
}
on constructor : //getting the tab title i need to set as active tab
this.route.data.subscribe(data => {
this.selectedTabTitle= data['type'];
});
HTML :
<ng-container *ngIf="condition">
<mat-tab-group (selectedTabChange)="tabchanged($event)"
[selectedIndex]="selectedTabIndex" #tabsgroup >
<mat-tab label="label 1">
<ng-template matTabContent>
<child-component> </child-component>
</ng-template>
</mat-tab>
<mat-tab label="label 2">
<ng-template matTabContent>
<child-component> </child-component>
</ng-template>
</mat-tab>
<mat-tab-group>
</ng-container>