From fb81f9704f3de56b0a49ed43fefa650d42b2263c Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 24 Nov 2014 23:03:30 -0600 Subject: [PATCH] fix(disconnect): move scope disconnect before enter --- js/angular/service/viewSwitcher.js | 5 ++-- test/unit/angular/directive/navView.unit.js | 28 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/js/angular/service/viewSwitcher.js b/js/angular/service/viewSwitcher.js index fc8b30cdab..5e899f8b4b 100644 --- a/js/angular/service/viewSwitcher.js +++ b/js/angular/service/viewSwitcher.js @@ -166,6 +166,9 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe var enteringData = getTransitionData(viewLocals, enteringEle, registerData.direction, enteringView); var transitionFn = $ionicConfig.transitions.views[enteringData.transition]; + // disconnect the leaving scope before reconnecting or creating a scope for the entering view + leavingEle && ionic.Utils.disconnectScope(leavingEle.scope()); + if (alreadyInDom) { // it was already found in the DOM, just reconnect the scope ionic.Utils.reconnectScope(enteringEle.scope()); @@ -345,8 +348,6 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe destroyViewEle(removableEle); - ionic.Utils.disconnectScope(leavingEle && leavingEle.scope()); - if (enteringEle.data(DATA_NO_CACHE)) { enteringEle.data(DATA_DESTROY_ELE, true); } diff --git a/test/unit/angular/directive/navView.unit.js b/test/unit/angular/directive/navView.unit.js index 8ea77cadcb..27945e2e48 100644 --- a/test/unit/angular/directive/navView.unit.js +++ b/test/unit/angular/directive/navView.unit.js @@ -480,6 +480,34 @@ describe('Ionic nav-view', function() { expect(divs.eq(0).attr('nav-view')).toBe('active'); })); + it('should disconnect and reconnect view scopes', inject(function ($state, $q, $timeout, $compile) { + elem.append($compile('
')(scope)); + + $state.go(page1State); + $q.flush(); + $timeout.flush(); + $timeout.flush(); + + var divs = elem.find('ion-nav-view').find('div'); + expect(divs.eq(0).scope().$$disconnected).toBeUndefined(); + + $state.go(page2State); + $q.flush(); + $timeout.flush(); + $timeout.flush(); + + divs = elem.find('ion-nav-view').find('div'); + expect(divs.eq(0).scope().$$disconnected).toBe(true); + expect(divs.eq(1).scope().$$disconnected).toBeUndefined(); + + $state.go(page1State); + $q.flush(); + $timeout.flush(); + $timeout.flush(); + divs = elem.find('ion-nav-view').find('div'); + expect(divs.eq(0).scope().$$disconnected).toBe(false); + })); + it('should not cache ion-nav-views that were forward when moving back', inject(function ($state, $q, $timeout, $compile, $ionicConfig) { elem.append($compile('
')(scope));