When I switch md-tabs often, Md-tabs switch correctly, but several md-tab-item elements have the class "md-active" at the same time, so I donβt see the active contents of the tab because it overlaps with the right contents of the tab.
According to my words, in the angular material, when we select a tab, angular first deselect the previous tab (hide the previously displayed content on the page) and display the contents of the selected tabs. By performing this process, angular skips the removal of the "md-active" class of the previously active tab.
Here is a fiddle to reproduce the behavior. This random behavior occurs with simultaneous clicks.
Wait 1 minute after clicking jsFiddle
angular.module('firstApplication', ['ngMaterial']).controller('tabController', tabController); function tabController ($scope) { $scope.boards = Array.from(Array(100).keys()); $scope.data = { selectedIndex: 0, secondLocked: true, secondLabel: "2", bottom: false }; $scope.next = function() { $scope.data.selectedIndex = Math.min($scope.data.selectedIndex + 1, 2) ; }; $scope.previous = function() { $scope.data.selectedIndex = Math.max($scope.data.selectedIndex - 1, 0); }; $scope.switch = function() { $scope.activeTabsCounter = $("md-tab-item.md-active").length; } $scope.switchTabs = function(){ clearInterval(interval); var i = $scope.boards.length - 1; var interval = setInterval(function() { if($scope.activeTabsCounter == 1) { if(i >= 0) $(".md-accent md-tab-item")[i--].click(); $scope.switchTabs(); } else { clearInterval(interval); } }, 100); } }
<link href="https://rawgit.com/angular/bower-material/master/angular-material.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.js"></script> <script src="https://rawgit.com/angular/bower-material/master/angular-material.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular-animate.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular-aria.js"></script> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <div ng-app="firstApplication"> <div id="tabContainer" ng-controller="tabController as ctrl" ng-cloak> <div> <br><br> <button ng-click="switchTabs()">Click here to switch tabs</button> <br><br> Current active Tabs: {{activeTabsCounter}} <br> </div> <md-content class="md-padding"> <md-tabs class="md-accent" md-selected="data.selectedIndex" md-align-tabs="{{data.bottom ? 'bottom' : 'top'}}"> <md-tab md-on-select="switch()" id="tab{{board}}" ng-repeat="board in boards"> <canvas id="canvas-{{board}}-1" width="1600" height="900"></canvas> <canvas id="canvas-{{board}}-2" width="1600" height="900"></canvas> <md-tab-label>{{board}}</md-tab-label> <md-tab-body>Item #{{board}} <br/>selectedIndex = {{board}};</md-tab-body> </md-tab> </md-tabs> </md-content> </div> </div>
I switch tabs in 100 ms, but in our application we also get this problem with a long time interval. We fire the board switch event using the socket.
source share