问题
I have four tabs using the latest AngularStrap
tab, every tab has a close button, and every tab pane using the latest ui-grid
.
- expected result: close the second tab, then show the third active tab, which can show the third tab title and tab pane correctly.
- but the actual result is: close the second tab, then show the third tab pane correctly, the third active tab title can't show correctly, it show the fourth active tab title.
html code:
<div data-fade="1" bs-active-pane="tabs.activeTab" bs-tabs>
<div ng-repeat="tab in tabs" data-title="{{ tab.title }}" name="{{ tab.title }}" disabled="{{ tab.disabled }}" ng-include src="tab.page" bs-pane></div>
</div>
js code:
// delete tab
closeTab = function(obj){
var index = obj.parentElement.dataset.index;
// remove your selected tab
$rootScope.tabs.splice(index, 1);
if(!angular.isUndefined($rootScope.tabs[index])){
// show the next active tab title.
$rootScope.tabs.activeTab = $rootScope.tabs[index].title;
}
}
can anyone help me? thank u very much!
回答1:
When you splice from the array the indices change because the element is removed so $rootScope.tabs.activeTab = $rootScope.tabs[index].title;
doesn't align anymore;
来源:https://stackoverflow.com/questions/34203064/not-show-active-tab-title-correctly-in-angularstrap-tab