I display several tabs with a loop ngFor using Angular Material tabs. This works properly however now I would like to open the second tab when initialised and not the first tab. Therefore, I add the property selectedIndex in the mat-tab-group but it doesn't work and still continues to open on the first tab.
HTML
<mat-tab-group class="col-10 offset-1" (selectedTabChange)="onTabChanged($event)" [selectedIndex]="1">
<mat-tab label={{tab.name}} *ngFor="let tab of tabs; let index = index">
<div>
Values: {{tab.values}}
</div>
</mat-tab>
</mat-tab-group>
The variable "tabs" is fetched with a service from the server in ngOnInit like this:
COMPONENT
this.api.getDataset(this.route.snapshot.params["experimentid"]).subscribe(
res => {
this.tabs = res;
},
err => {
console.log(err);
}
);
I think it comes from here because if I set the tabs manually without requesting to the server it works. Like this:
this.tabs = [{name: "X2", values: "52"}, {name: "Z2", values: "52"}, {name: "R2", values: "52"}]