Material design md-tabs with angled

I have a question about md-tabs control in material design. I am using md-tabs with Angularjs in one of the pages and it works great. I also have an md button on this page and we want the user to click that button and we will move to the next tab. I'm new to this stuff - angular and would appreciate it if someone could guide me in the right direction.

+3


source to share


2 answers


You can use the attribute md-selected

in the directive md-tabs

. md-tabs

uses the attribute md-selected

to decide which tab is selected. Therefore, you can simply refresh $scope.selectedTab

on the click of yours md-button

to select the tab you want.

Take a look at this piece of code:



angular.module("material", ["ngMaterial", "ngAnimate"])

.controller("tabCtrl", ["$scope", function($scope) {
    $scope.selectedTab = 0;
    
    $scope.changeTab = function() {
        if ($scope.selectedTab === 2) {
            $scope.selectedTab = 0;
        }
        else {
            $scope.selectedTab++;
        }
        
    }
}]);
      

.tab-content {
    margin: 20px 0 0 0;
    text-align:center;
}

.tab-container {
    height:120px;
}

.tab-change-row {
    text-align:center;
}

.tab-change-btn {
    display: inline-block
}
      

<link href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.4/angular-material.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script>

    <script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.4/angular-material.min.js"></script>
<body ng-app="material">
    <div ng-controller="tabCtrl">
        <div class="tab-container">
            <md-tabs md-selected="selectedTab">
                <md-tab label="One">
                    <p class="tab-content">Tab One content</p>
                </md-tab>
                <md-tab label="Two">
                    <p class="tab-content">Tab Two content</p>
                </md-tab>
                <md-tab label="Three">
                    <p class="tab-content">Tab Three content</p>
                </md-tab>
            </md-tabs>      
        </div>
       
        
        <div class="tab-change-row">
            <md-button class="tab-btn md-raised" ng-click="changeTab()">Change Tab</md-button>    
        </div>
        
    </div>
</body>
      

Run code


+8


source


we can use " selectedIndex

" for this, put the tab index value as selectedindex, then it will activate this tab, we can use selectedIndex in <md-tab-group>

, it will start from zero. See tabs for more details



0


source







All Articles