|
73 | 73 | * When the `on` expression value changes and an animation is triggered then each of the elements within
|
74 | 74 | * will all animate without the block being applied to child elements.
|
75 | 75 | *
|
| 76 | + * ## Are animations run when the application starts? |
| 77 | + * No they are not. When an application is bootstrapped Angular will disable animations from running to avoid |
| 78 | + * a frenzy of animations from being triggered as soon as the browser has rendered the screen. For this to work, |
| 79 | + * Angular will wait for two digest cycles until enabling animations. From there on, any animation-triggering |
| 80 | + * layout changes in the application will be handled naturally. |
| 81 | + * |
| 82 | + * In addition, upon bootstrap, if the routing system or any directives or load remote data (via $http) then Angular |
| 83 | + * will automatically extend the wait time to enable animations once **all** of the outbound HTTP requests |
| 84 | + * are complete. |
| 85 | + * |
76 | 86 | * <h2>CSS-defined Animations</h2>
|
77 | 87 | * The animate service will automatically apply two CSS classes to the animated element and these two CSS classes
|
78 | 88 | * are designed to contain the start and end CSS styling. Both CSS transitions and keyframe animations are supported
|
@@ -394,24 +404,41 @@ angular.module('ngAnimate', ['ng'])
|
394 | 404 | return extractElementNode(elm1) == extractElementNode(elm2);
|
395 | 405 | }
|
396 | 406 |
|
397 |
| - $provide.decorator('$animate', ['$delegate', '$injector', '$sniffer', '$rootElement', '$$asyncCallback', '$rootScope', '$document', |
398 |
| - function($delegate, $injector, $sniffer, $rootElement, $$asyncCallback, $rootScope, $document) { |
| 407 | + $provide.decorator('$animate', |
| 408 | + ['$delegate', '$injector', '$sniffer', '$rootElement', '$$asyncCallback', '$rootScope', '$document', '$$templateRequest', |
| 409 | + function($delegate, $injector, $sniffer, $rootElement, $$asyncCallback, $rootScope, $document, $$templateRequest) { |
399 | 410 |
|
400 |
| - var globalAnimationCounter = 0; |
401 | 411 | $rootElement.data(NG_ANIMATE_STATE, rootAnimateState);
|
402 | 412 |
|
403 | 413 | // disable animations during bootstrap, but once we bootstrapped, wait again
|
404 |
| - // for another digest until enabling animations. The reason why we digest twice |
405 |
| - // is because all structural animations (enter, leave and move) all perform a |
406 |
| - // post digest operation before animating. If we only wait for a single digest |
407 |
| - // to pass then the structural animation would render its animation on page load. |
408 |
| - // (which is what we're trying to avoid when the application first boots up.) |
409 |
| - $rootScope.$$postDigest(function() { |
410 |
| - $rootScope.$$postDigest(function() { |
411 |
| - rootAnimateState.running = false; |
412 |
| - }); |
413 |
| - }); |
| 414 | + // for another digest until enabling animations. Enter, leave and move require |
| 415 | + // a follow-up digest so having a watcher here is enough to let both digests pass. |
| 416 | + // However, when any directive or view templates are downloaded then we need to |
| 417 | + // handle postpone enabling animations until they are fully completed and then... |
| 418 | + var watchFn = $rootScope.$watch( |
| 419 | + function() { return $$templateRequest.totalPendingRequests; }, |
| 420 | + function(val, oldVal) { |
| 421 | + if (oldVal === 0) { |
| 422 | + if (val === 0) { |
| 423 | + $rootScope.$$postDigest(onApplicationReady); |
| 424 | + } |
| 425 | + } else if(val === 0) { |
| 426 | + // ...when the template has been downloaded we digest twice again until the |
| 427 | + // animations are set to enabled (since enter, leave and move require a |
| 428 | + // follow-up). |
| 429 | + $rootScope.$$postDigest(function() { |
| 430 | + $rootScope.$$postDigest(onApplicationReady); |
| 431 | + }); |
| 432 | + } |
| 433 | + } |
| 434 | + ); |
414 | 435 |
|
| 436 | + function onApplicationReady() { |
| 437 | + rootAnimateState.running = false; |
| 438 | + watchFn(); |
| 439 | + } |
| 440 | + |
| 441 | + var globalAnimationCounter = 0; |
415 | 442 | var classNameFilter = $animateProvider.classNameFilter();
|
416 | 443 | var isAnimatableClassName = !classNameFilter
|
417 | 444 | ? function() { return true; }
|
|
0 commit comments