Skip to content

Commit 2ba12fc

Browse files
author
danielgarciagil
committed
Update tabs.js
avoid launch select callback on destroy event
1 parent 9030d2c commit 2ba12fc

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/tabs/tabs.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ angular.module('ui.bootstrap.tabs', [])
3636
};
3737

3838
ctrl.removeTab = function removeTab(tab) {
39-
var index = tabs.indexOf(tab);
40-
//Select a new tab if the tab to be removed is selected
41-
if (tab.active && tabs.length > 1) {
42-
//If this is the last tab, select the previous tab. else, the next tab.
43-
var newActiveIndex = index == tabs.length - 1 ? index - 1 : index + 1;
44-
ctrl.select(tabs[newActiveIndex]);
39+
if( ! $scope.destroying ){
40+
var index = tabs.indexOf(tab);
41+
//Select a new tab if the tab to be removed is selected
42+
if (tab.active && tabs.length > 1) {
43+
//If this is the last tab, select the previous tab. else, the next tab.
44+
var newActiveIndex = index == tabs.length - 1 ? index - 1 : index + 1;
45+
ctrl.select(tabs[newActiveIndex]);
46+
}
47+
tabs.splice(index, 1);
4548
}
46-
tabs.splice(index, 1);
49+
};
50+
51+
ctrl.destroyTabset = function destroyTabset() {
52+
$scope.destroying = true;
53+
tabs = [];
4754
};
4855
}])
4956

@@ -90,6 +97,10 @@ angular.module('ui.bootstrap.tabs', [])
9097
link: function(scope, element, attrs) {
9198
scope.vertical = angular.isDefined(attrs.vertical) ? scope.$parent.$eval(attrs.vertical) : false;
9299
scope.justified = angular.isDefined(attrs.justified) ? scope.$parent.$eval(attrs.justified) : false;
100+
scope.destroying = false;
101+
scope.$on('$destroy', function() {
102+
ctrl.destroyTabset();
103+
});
93104
}
94105
};
95106
})

0 commit comments

Comments
 (0)