diff --git a/js/angular/service/viewSwitcher.js b/js/angular/service/viewSwitcher.js
index b49bcd5841..197fb63950 100644
--- a/js/angular/service/viewSwitcher.js
+++ b/js/angular/service/viewSwitcher.js
@@ -178,7 +178,8 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe
// if the current state has cache:false
// or the element has cache-view="false" attribute
- if (viewState(viewLocals).cache === false || viewState(viewLocals).cache === 'false' || enteringEle.attr('cache-view') == 'false') {
+ if (viewState(viewLocals).cache === false || viewState(viewLocals).cache === 'false' ||
+ enteringEle.attr('cache-view') == 'false' || $ionicConfig.views.maxCache() === 0) {
enteringEle.data(DATA_NO_CACHE, true);
}
diff --git a/test/unit/angular/directive/navView.unit.js b/test/unit/angular/directive/navView.unit.js
index 334a84bda0..1666aa44df 100644
--- a/test/unit/angular/directive/navView.unit.js
+++ b/test/unit/angular/directive/navView.unit.js
@@ -104,13 +104,27 @@ describe('Ionic nav-view', function() {
cache: false
},
rootView1State = {
- cache: 'false',
views: {
'root': {
template: 'rootView1State'
}
}
},
+ rootView2State = {
+ views: {
+ 'root': {
+ template: 'rootView2State'
+ }
+ }
+ },
+ rootView1NoCacheState = {
+ cache: 'false',
+ views: {
+ 'root': {
+ template: 'rootView1NoCacheState'
+ }
+ }
+ },
tabAbstractState = {
abstract: true,
views: {
@@ -183,7 +197,9 @@ describe('Ionic nav-view', function() {
.state('tabAbstract.tab2page1', tab2page1State)
.state('tabAbstract.tab3page1', tab3page1State)
.state('tabAbstract.tab3page2', tab3page2NoCacheState)
- .state('rootView1', rootView1State);
+ .state('rootView1', rootView1State)
+ .state('rootView2', rootView2State)
+ .state('rootView1NoCache', rootView1NoCacheState);
}));
beforeEach(inject(function(_$compile_, $ionicConfig, $rootScope) {
@@ -941,9 +957,40 @@ describe('Ionic nav-view', function() {
expect(tab3Ele.getAttribute('nav-view')).toBe('cached');
}));
- it('should not cache ion-views when going between history and its the first load', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
+ it('should not cache ion-views when going between history and its the first load, stateParam cache=false', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
elem.append($compile('')(scope));
+ $state.go(rootView1NoCacheState);
+ $q.flush();
+ $timeout.flush();
+ expect(elem.find('ion-nav-view').find('ion-view').length).toBe(1);
+ expect(elem.find('ion-nav-view').find('ion-view').eq(0).text()).toBe('rootView1NoCacheState');
+
+ $state.go(tab1page1State);
+ $q.flush();
+ $timeout.flush();
+
+ var tab1Ele = elem[0].querySelector('ion-nav-view[name="tab1"]');
+ expect(tab1Ele.getAttribute('nav-view')).toBe('active');
+
+ expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
+
+ $state.go(tab2page1State);
+ $q.flush();
+ $timeout.flush();
+
+ var tab2Ele = elem[0].querySelector('ion-nav-view[name="tab2"]');
+ expect(tab2Ele.getAttribute('nav-view')).toBe('active');
+
+ tab1Ele = elem[0].querySelector('ion-nav-view[name="tab1"]');
+ expect(tab1Ele.getAttribute('nav-view')).toBe('cached');
+ }));
+
+ it('should not cache ion-views when going between history and its the first load, maxCache(0)', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
+ elem.append($compile('')(scope));
+
+ $ionicConfig.views.maxCache(0);
+
$state.go(rootView1State);
$q.flush();
$timeout.flush();
@@ -956,7 +1003,52 @@ describe('Ionic nav-view', function() {
var tab1Ele = elem[0].querySelector('ion-nav-view[name="tab1"]');
expect(tab1Ele.getAttribute('nav-view')).toBe('active');
+ expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
+ $state.go(tab2page1State);
+ $q.flush();
+ $timeout.flush();
+
+ var tab2Ele = elem[0].querySelector('ion-nav-view[name="tab2"]');
+ expect(tab2Ele.getAttribute('nav-view')).toBe('active');
+
+ tab1Ele = elem[0].querySelector('ion-nav-view[name="tab1"]');
+ expect(tab1Ele).toBe(null);
+ }));
+
+ it('should not cache any views when going root1 to tabs to root 2', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
+ elem.append($compile('')(scope));
+
+ $ionicConfig.views.maxCache(0);
+
+ $state.go(rootView1State);
+ $q.flush();
+ $timeout.flush();
+ expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
+
+ $state.go(tab1page1State);
+ $q.flush();
+ $timeout.flush();
+ expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
+
+ $state.go(rootView2State);
+ $q.flush();
+ $timeout.flush();
+ expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
+
+ $state.go(rootView1State);
+ $q.flush();
+ $timeout.flush();
+ expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
+
+ $state.go(tab1page1State);
+ $q.flush();
+ $timeout.flush();
+ expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
+
+ $state.go(rootView2State);
+ $q.flush();
+ $timeout.flush();
expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
}));