feat(clearCache): create $ionicHistory.clearCache()

This commit is contained in:
Adam Bradley
2014-11-21 17:09:53 -06:00
parent 5a28bbb1bd
commit 2683ffd075
5 changed files with 106 additions and 13 deletions

View File

@@ -6,9 +6,10 @@ IonicModule
'$compile',
'$controller',
'$ionicNavBarDelegate',
'$ionicNavViewDelegate',
'$ionicHistory',
'$ionicViewSwitcher',
function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate, $ionicHistory, $ionicViewSwitcher) {
function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate, $ionicNavViewDelegate, $ionicHistory, $ionicViewSwitcher) {
var DATA_ELE_IDENTIFIER = '$eleId';
var VIEW_STATUS_ACTIVE = 'active';
@@ -36,6 +37,9 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
var viewData = { name: navViewName, state: null };
$element.data('$uiView', viewData);
var deregisterInstance = $ionicNavViewDelegate._registerInstance(self, $attrs.delegateHandle);
$scope.$on('$destroy', deregisterInstance);
return viewData;
};
@@ -154,6 +158,18 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
};
self.clearCache = function() {
var viewElements = $element.children();
for (var x = 0, l = viewElements.length; x < l; x++) {
if (navViewAttr(viewElements.eq(x)) == VIEW_STATUS_CACHED) {
$ionicViewSwitcher.destroyViewEle(viewElements.eq(x));
}
}
};
self.getViewElements = function() {
return $element.children();
};