@@ -36,14 +36,21 @@ angular.module('ui.bootstrap.tabs', [])
36
36
} ;
37
37
38
38
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 ) ;
45
48
}
46
- tabs . splice ( index , 1 ) ;
49
+ } ;
50
+
51
+ ctrl . destroyTabset = function destroyTabset ( ) {
52
+ $scope . destroying = true ;
53
+ tabs = [ ] ;
47
54
} ;
48
55
} ] )
49
56
@@ -90,6 +97,10 @@ angular.module('ui.bootstrap.tabs', [])
90
97
link : function ( scope , element , attrs ) {
91
98
scope . vertical = angular . isDefined ( attrs . vertical ) ? scope . $parent . $eval ( attrs . vertical ) : false ;
92
99
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
+ } ) ;
93
104
}
94
105
} ;
95
106
} )
0 commit comments