diff --git a/js/angular/controller/navViewController.js b/js/angular/controller/navViewController.js index a16386e862..19aa5e4d73 100644 --- a/js/angular/controller/navViewController.js +++ b/js/angular/controller/navViewController.js @@ -164,9 +164,13 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate, if (viewElement.data(DATA_DESTROY_ELE) || viewElement.data(DATA_NO_CACHE)) { // this element shouldn't stay cached $ionicViewSwitcher.destroyViewEle(viewElement); + } else { // keep in the DOM, mark as cached navViewAttr(viewElement, VIEW_STATUS_CACHED); + + // disconnect the leaving scope + ionic.Utils.disconnectScope(viewElement.scope()); } } } diff --git a/js/angular/service/viewSwitcher.js b/js/angular/service/viewSwitcher.js index 126229c3f2..6ee378a768 100644 --- a/js/angular/service/viewSwitcher.js +++ b/js/angular/service/viewSwitcher.js @@ -102,9 +102,6 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe }, render: function(registerData, callback) { - // 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()); diff --git a/test/unit/angular/directive/navView.unit.js b/test/unit/angular/directive/navView.unit.js index 2707668a48..d734f548eb 100644 --- a/test/unit/angular/directive/navView.unit.js +++ b/test/unit/angular/directive/navView.unit.js @@ -570,6 +570,40 @@ describe('Ionic nav-view', function() { expect(divs.eq(0).scope().$$disconnected).toBe(false); })); + it('should have connected scopes at the time of lifecycle events', inject(function ($state, $q, $timeout, $compile) { + elem.append($compile('