@@ -411,20 +411,21 @@ 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 2 digests 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
+ // compile. The $templateRequest.totalPendingRequests variable keeps track of
416
+ // all of the remote templates being currently downloaded. If there are no
417
+ // templates currently downloading the watcher will still fire anyway.
418
+ var deregisterWatch = $rootScope . $watch (
420
419
function ( ) { return $templateRequest . totalPendingRequests ; } ,
421
420
function ( val , oldVal ) {
422
421
if ( val !== 0 ) return ;
423
- watchFn ( ) ;
422
+ deregisterWatch ( ) ;
424
423
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.
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. This basically means that the page is
428
+ // fully downloaded and compiled before any animations are triggered.
428
429
$rootScope . $$postDigest ( function ( ) {
429
430
$rootScope . $$postDigest ( function ( ) {
430
431
rootAnimateState . running = false ;
0 commit comments