@@ -411,34 +411,31 @@ angular.module('ngAnimate', ['ng'])
411
411
412
412
$rootElement . data ( NG_ANIMATE_STATE , rootAnimateState ) ;
413
413
414
- // disable animations during bootstrap, but once we bootstrapped, wait again
415
- // for another digest until enabling animations. Enter, leave and move require
416
- // a follow-up digest so having a watcher here is enough to let both digests pass.
417
- // However, when any directive or view templates are downloaded then we need to
418
- // handle postpone enabling animations until they are fully completed and then...
419
- var watchFn = $rootScope . $watch (
414
+ // Wait until all directive and route-related templates are downloaded and
415
+ // compiled. The $templateRequest.totalPendingRequests variable keeps track of
416
+ // all of the remote templates being currently downloaded. If there are no
417
+ // templates currently downloading then the watcher will still fire anyway.
418
+ var deregisterWatch = $rootScope . $watch (
420
419
function ( ) { return $templateRequest . totalPendingRequests ; } ,
421
420
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).
421
+ if ( val !== 0 ) return ;
422
+ deregisterWatch ( ) ;
423
+
424
+ // Now that all templates have been downloaded, $animate will wait until
425
+ // the post digest queue is empty before enabling animations. By having two
426
+ // calls to $postDigest calls we can ensure that the flag is enabled at the
427
+ // very end of the post digest queue. Since all of the animations in $animate
428
+ // use $postDigest, it's important that the code below executes at the end.
429
+ // This basically means that the page is fully downloaded and compiled before
430
+ // any animations are triggered.
431
+ $rootScope . $$postDigest ( function ( ) {
430
432
$rootScope . $$postDigest ( function ( ) {
431
- $rootScope . $$postDigest ( onApplicationReady ) ;
433
+ rootAnimateState . running = false ;
432
434
} ) ;
433
- }
435
+ } ) ;
434
436
}
435
437
) ;
436
438
437
- function onApplicationReady ( ) {
438
- rootAnimateState . running = false ;
439
- watchFn ( ) ;
440
- }
441
-
442
439
var globalAnimationCounter = 0 ;
443
440
var classNameFilter = $animateProvider . classNameFilter ( ) ;
444
441
var isAnimatableClassName = ! classNameFilter
0 commit comments