Skip to content

Commit 08ac2d1

Browse files
committed
fix($animate): wait two until two digests are over until enabling animations
Even when no remote templates are to be downloaded, wait two digests until enabling animations since all structural digests perform a post digest before running animations. Closes angular#8844
1 parent 9057ed2 commit 08ac2d1

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/ngAnimate/animate.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -412,33 +412,27 @@ angular.module('ngAnimate', ['ng'])
412412
$rootElement.data(NG_ANIMATE_STATE, rootAnimateState);
413413

414414
// disable animations during bootstrap, but once we bootstrapped, wait again
415-
// for another digest until enabling animations. Enter, leave and move require
415+
// for another 2 digests until enabling animations. Enter, leave and move require
416416
// a follow-up digest so having a watcher here is enough to let both digests pass.
417417
// However, when any directive or view templates are downloaded then we need to
418418
// handle postpone enabling animations until they are fully completed and then...
419419
var watchFn = $rootScope.$watch(
420420
function() { return $templateRequest.totalPendingRequests; },
421421
function(val, oldVal) {
422-
if (oldVal === 0) {
423-
if (val === 0) {
424-
$rootScope.$$postDigest(onApplicationReady);
425-
}
426-
} else if(val === 0) {
427-
// ...when the template has been downloaded we digest twice again until the
428-
// animations are set to enabled (since enter, leave and move require a
429-
// follow-up).
422+
if (val !== 0) return;
423+
watchFn();
424+
425+
// ...when the template has been downloaded we digest twice again until the
426+
// animations are set to enabled (since enter, leave and move require a
427+
// follow-up). The same approach applies when there are no templates to download.
428+
$rootScope.$$postDigest(function() {
430429
$rootScope.$$postDigest(function() {
431-
$rootScope.$$postDigest(onApplicationReady);
430+
rootAnimateState.running = false;
432431
});
433-
}
432+
});
434433
}
435434
);
436435

437-
function onApplicationReady() {
438-
rootAnimateState.running = false;
439-
watchFn();
440-
}
441-
442436
var globalAnimationCounter = 0;
443437
var classNameFilter = $animateProvider.classNameFilter();
444438
var isAnimatableClassName = !classNameFilter

test/ng/directive/ngClassSpec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,10 @@ describe('ngClass animations', function() {
434434
});
435435
inject(function($compile, $rootScope, $browser, $rootElement, $animate, $timeout, $document) {
436436

437-
// Animations are enabled right away since there are no remote HTTP template requests
437+
// Animations need to digest twice in order to be enabled regardless if there are no template HTTP requests.
438+
$rootScope.$digest();
439+
digestQueue.shift()();
440+
438441
$rootScope.$digest();
439442
digestQueue.shift()();
440443

0 commit comments

Comments
 (0)