Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 7237767

Browse files
committed
fix(tabs): remove tabs all at once on ctrl destroy
Closes #437
1 parent 08cb638 commit 7237767

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/components/tabs/js/tabItemController.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ function TabItemController(scope, element, $compile, $animate, $mdSwipe, $mdUtil
6868
* as in an ng-repeat
6969
*/
7070
function onRemove() {
71-
$animate.leave(self.contentContainer).then(function()
72-
{
71+
$animate.leave(self.contentContainer).then(function() {
7372
self.contentScope && self.contentScope.$destroy();
7473
self.contentScope = null;
7574
});

src/components/tabs/js/tabsController.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ function MdTabsController(scope, element, $mdUtil) {
3535

3636
self.swipe = swipe;
3737

38+
scope.$on('$destroy', function() {
39+
self.deselect(self.selected());
40+
for (var i = tabsList.count() - 1; i >= 0; i--) {
41+
self.remove(tabsList[i], true);
42+
}
43+
});
44+
3845
// Get the selected tab
3946
function selected() {
4047
return self.itemAt(scope.selectedIndex);
@@ -58,10 +65,12 @@ function MdTabsController(scope, element, $mdUtil) {
5865
scope.$broadcast('$mdTabsChanged');
5966
}
6067

61-
function remove(tab) {
68+
function remove(tab, noReselect) {
6269
if (!tabsList.contains(tab)) return;
6370

64-
if (self.selected() === tab) {
71+
if (noReselect) {
72+
73+
} else if (self.selected() === tab) {
6574
if (tabsList.count() > 1) {
6675
self.select(self.previous() || self.next());
6776
} else {

0 commit comments

Comments
 (0)