From 767362bebd68af6e946b6290adff11d87db293a9 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 2 Dec 2014 11:50:27 -0600 Subject: [PATCH] fix(tabs): remove unselected tabs on clearCache --- js/angular/controller/navViewController.js | 9 +++++++-- js/angular/directive/tab.js | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/js/angular/controller/navViewController.js b/js/angular/controller/navViewController.js index 6c9b350b2d..bb7af55ab5 100644 --- a/js/angular/controller/navViewController.js +++ b/js/angular/controller/navViewController.js @@ -161,10 +161,15 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate, self.clearCache = function() { var viewElements = $element.children(); + var viewElement, viewScope; for (var x = 0, l = viewElements.length; x < l; x++) { - if (navViewAttr(viewElements.eq(x)) == VIEW_STATUS_CACHED) { - $ionicViewSwitcher.destroyViewEle(viewElements.eq(x)); + viewElement = viewElements.eq(x); + if (navViewAttr(viewElement) == VIEW_STATUS_CACHED) { + $ionicViewSwitcher.destroyViewEle(viewElement); + } else if (navViewAttr(viewElement) == VIEW_STATUS_ACTIVE) { + viewScope = viewElement.scope(); + viewScope && viewScope.$broadcast('$ionicView.clearCache'); } } diff --git a/js/angular/directive/tab.js b/js/angular/directive/tab.js index e1c82c84fc..dc2356b7f0 100644 --- a/js/angular/directive/tab.js +++ b/js/angular/directive/tab.js @@ -169,20 +169,30 @@ function($compile, $ionicConfig, $ionicBind, $ionicViewSwitcher) { } else { // do not keep tabs in the DOM - childScope && childScope.$destroy(); - childElement && childElement.remove(); - isTabContentAttached = childScope = childElement = null; + destroyTab(); } } } + function destroyTab() { + childScope && childScope.$destroy(); + isTabContentAttached && childElement && childElement.remove(); + isTabContentAttached = childScope = childElement = null; + } + $scope.$watch('$tabSelected', tabSelected); $scope.$on('$ionicView.afterEnter', function() { $ionicViewSwitcher.viewEleIsActive(childElement, $scope.$tabSelected); }); + $scope.$on('$ionicView.clearCache', function() { + if (!$scope.$tabSelected) { + destroyTab(); + } + }); + }; } };