1

I have an mdTabs setup like this:

<md-tabs md-dynamic-height md-border-bottom>
  <md-tab label="The first tab" id="first-tab-wrapper" class="tab-wrapper">
  </md-tab>
  <md-tab label="The second tab" id="second-tab-wrapper" class="tab-wrapper">
  </md-tab>
</md-tabs>
<button>GO TO SECOND TAB</button>

When the user clicks the button, the browser should go to the second mdTab. How do I do this?

Kyle Krzeski
  • 6,183
  • 6
  • 41
  • 52
Username
  • 3,463
  • 11
  • 68
  • 111
  • take a look at https://stackoverflow.com/questions/41937176/programmatically-select-md-tab-in-angular-2-material – bajji Jul 11 '17 at 18:53

1 Answers1

2

You can use md-selected to keep track of the tab:

Index of the active/selected tab

HTML:

<md-tabs md-dynamic-height md-border-bottom md-selected="selectedTab">
  <md-tab label="The first tab" id="first-tab-wrapper" class="tab-wrapper">
  </md-tab>
  <md-tab label="The second tab" id="second-tab-wrapper" class="tab-wrapper">
  </md-tab>
</md-tabs>
<button ng-click="selectTab()">GO TO SECOND TAB</button>

JavaScript:

$scope.selectTab = function() {
  //go to second tab
  $scope.selectedTab = 1;
}
Kyle Krzeski
  • 6,183
  • 6
  • 41
  • 52