Skip to content

Commit

Permalink
Update tabs.js
Browse files Browse the repository at this point in the history
avoid launch select callback on destroy event
  • Loading branch information
danielgarciagil committed Jul 28, 2014
1 parent 9030d2c commit 2ba12fc
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ angular.module('ui.bootstrap.tabs', [])
};

ctrl.removeTab = function removeTab(tab) {
var index = tabs.indexOf(tab);
//Select a new tab if the tab to be removed is selected
if (tab.active && tabs.length > 1) {
//If this is the last tab, select the previous tab. else, the next tab.
var newActiveIndex = index == tabs.length - 1 ? index - 1 : index + 1;
ctrl.select(tabs[newActiveIndex]);
if( ! $scope.destroying ){
var index = tabs.indexOf(tab);
//Select a new tab if the tab to be removed is selected
if (tab.active && tabs.length > 1) {
//If this is the last tab, select the previous tab. else, the next tab.
var newActiveIndex = index == tabs.length - 1 ? index - 1 : index + 1;
ctrl.select(tabs[newActiveIndex]);
}
tabs.splice(index, 1);
}
tabs.splice(index, 1);
};

ctrl.destroyTabset = function destroyTabset() {
$scope.destroying = true;
tabs = [];
};
}])

Expand Down Expand Up @@ -90,6 +97,10 @@ angular.module('ui.bootstrap.tabs', [])
link: function(scope, element, attrs) {
scope.vertical = angular.isDefined(attrs.vertical) ? scope.$parent.$eval(attrs.vertical) : false;
scope.justified = angular.isDefined(attrs.justified) ? scope.$parent.$eval(attrs.justified) : false;
scope.destroying = false;
scope.$on('$destroy', function() {
ctrl.destroyTabset();
});
}
};
})
Expand Down

3 comments on commit 2ba12fc

@wkjesus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctrl is not defined on line 102 ctrl.destroyTabset();

@wkjesus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this lines

ctrl.destroyTabset();

to this
scope.destroying = true;
tabs = [];

@danielgarciagil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

Please sign in to comment.