Programmatically select mat-tab in Angular 2 material using mat-tab-group

前端 未结 4 1799
误落风尘
误落风尘 2020-12-13 23:53

How can I select a specific tab when an event occurs?

I tried with [selectedIndex]=\"selectedTab\" changing the selectedTab to the tab ind

4条回答
  •  佛祖请我去吃肉
    2020-12-14 00:40

    In case it helps anyone, it is also possible to set selectedIndex on the MatTabGroup in your component.

    If your HTML has: , you can get a reference to it in the component using @ViewChild('tabs') tabGroup: MatTabGroup;.

    Then you can do this.tabGroup.selectedIndex = newIndex; in the OnInit function, or elsewhere.

提交回复
热议问题