Angular Material Tabs SelectedIndex 0 not working

2019-06-17 04:29发布

I have a tab group in Angular. I want that by default the first tab will be selected.
However, when I set the selectedIndex to 0, it doesn't select the first tab, while setting it to 1 or 2 does select the other tabs.

This is my app.component.html:

<mat-toolbar color="primary">
  <span color="white">קשת נחושה</span>
  <span class="spacer"></span>
  <button mat-icon-button>
        <mat-icon class="example-icon">more_vert</mat-icon>
  </button>
</mat-toolbar>
<mat-tab-group mat-stretch-tabs [selectedIndex]="0" (focusChange)="selectedTab($event)">
  <mat-tab>
    <ng-template mat-tab-label>
      <mat-icon>home</mat-icon>
    </ng-template>
  </mat-tab>
  <mat-tab>
    <ng-template mat-tab-label>
      <mat-icon>book</mat-icon>
    </ng-template>
  </mat-tab>
  <mat-tab>
    <ng-template mat-tab-label>
      <mat-icon>message</mat-icon>
    </ng-template>
  </mat-tab>
</mat-tab-group>
<router-outlet></router-outlet>

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-06-17 05:11

it's a bug but you can use 2 ways data binding, it works

<md-tab-group [(selectedIndex)]="value">
查看更多
登录 后发表回答