Skip to content

Commit

Permalink
fix(disconnect): move scope disconnect before enter
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Nov 25, 2014
1 parent 03d2f1c commit fb81f97
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions js/angular/service/viewSwitcher.js
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
Expand Down
28 changes: 28 additions & 0 deletions test/unit/angular/directive/navView.unit.js
Expand Up @@ -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('<div><ion-nav-view></ion-nav-view></div>')(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('<div><ion-nav-view></ion-nav-view></div>')(scope));

Expand Down

0 comments on commit fb81f97

Please sign in to comment.