Skip to content

Commit

Permalink
fix(viewDirective): $destroy event is triggered before animation ends
Browse files Browse the repository at this point in the history
when view is animated using ngAnimate, $destroy event is triggered before
animation ends.

closes angular-ui#1643
  • Loading branch information
Teemu Kokkonen committed Oct 29, 2015
1 parent d23e9fa commit 4648d7e
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions src/viewDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@
* functionality, call `$uiViewScrollProvider.useAnchorScroll()`.*
*
* @param {string=} onload Expression to evaluate whenever the view updates.
*
*
* @example
* A view can be unnamed or named.
* A view can be unnamed or named.
* <pre>
* <!-- Unnamed -->
* <div ui-view></div>
*
* <div ui-view></div>
*
* <!-- Named -->
* <div ui-view="viewName"></div>
* </pre>
*
* You can only have one unnamed view within any template (or root html). If you are only using a
* You can only have one unnamed view within any template (or root html). If you are only using a
* single view and it is unnamed then you can populate it like so:
* <pre>
* <div ui-view></div>
* <div ui-view></div>
* $stateProvider.state("home", {
* template: "<h1>HELLO!</h1>"
* })
* </pre>
*
*
* The above is a convenient shortcut equivalent to specifying your view explicitly with the {@link ui.router.state.$stateProvider#views `views`}
* config property, by name, in this case an empty name:
* <pre>
Expand All @@ -54,33 +54,33 @@
* "": {
* template: "<h1>HELLO!</h1>"
* }
* }
* }
* })
* </pre>
*
* But typically you'll only use the views property if you name your view or have more than one view
* in the same template. There's not really a compelling reason to name a view if its the only one,
*
* But typically you'll only use the views property if you name your view or have more than one view
* in the same template. There's not really a compelling reason to name a view if its the only one,
* but you could if you wanted, like so:
* <pre>
* <div ui-view="main"></div>
* </pre>
* </pre>
* <pre>
* $stateProvider.state("home", {
* views: {
* "main": {
* template: "<h1>HELLO!</h1>"
* }
* }
* }
* })
* </pre>
*
*
* Really though, you'll use views to set up multiple views:
* <pre>
* <div ui-view></div>
* <div ui-view="chart"></div>
* <div ui-view="data"></div>
* <div ui-view="chart"></div>
* <div ui-view="data"></div>
* </pre>
*
*
* <pre>
* $stateProvider.state("home", {
* views: {
Expand All @@ -93,7 +93,7 @@
* "data": {
* template: "<data_thing/>"
* }
* }
* }
* })
* </pre>
*
Expand Down Expand Up @@ -190,32 +190,45 @@ function $ViewDirective( $state, $injector, $uiViewScroll, $interpolate)
updateView(true);

function cleanupLastView() {
if (previousEl) {
previousEl.remove();
previousEl = null;
var _previousEl = previousEl;
var _currentScope = currentScope;

if (_currentScope) {
_currentScope._willBeDestroyed = true;
}

if (currentScope) {
currentScope.$destroy();
currentScope = null;
function cleanOld() {
if (_previousEl) {
_previousEl.remove();
}

if (_currentScope) {
_currentScope.$destroy();
}
}

if (currentEl) {
renderer.leave(currentEl, function() {
cleanOld();
previousEl = null;
});

previousEl = currentEl;
currentEl = null;
} else {
cleanOld();
previousEl = null;
}

currentEl = null;
currentScope = null;
}

function updateView(firstTime) {
var newScope,
name = getUiViewName(scope, attrs, $element, $interpolate),
previousLocals = name && $state.$current && $state.$current.locals[name];

if (!firstTime && previousLocals === latestLocals) return; // nothing to do
if (!firstTime && previousLocals === latestLocals || scope._willBeDestroyed) return; // nothing to do
newScope = scope.$new();
latestLocals = $state.$current.locals[name];

Expand Down

0 comments on commit 4648d7e

Please sign in to comment.