Skip to content

Commit bee14ed

Browse files
committed
fix(ngAnimate): ensure that animations work when the app is bootstrapped on the document node
Closes angular#11574
1 parent 1a0bcb1 commit bee14ed

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/ngAnimate/animateQueue.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
491491
var animateChildren;
492492

493493
while (parent && parent.length) {
494+
if (!rootElementDetected) {
495+
// angular doesn't want to attempt to animate elements outside of the application
496+
// therefore we need to ensure that the rootElement is an ancestor of the current element
497+
rootElementDetected = isMatchingElement(parent, $rootElement);
498+
}
499+
494500
var parentNode = parent[0];
495501
if (parentNode.nodeType !== ELEMENT_NODE) {
496502
// no point in inspecting the #document element
@@ -515,12 +521,6 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
515521
// there is no need to continue traversing at this point
516522
if (parentAnimationDetected && animateChildren === false) break;
517523

518-
if (!rootElementDetected) {
519-
// angular doesn't want to attempt to animate elements outside of the application
520-
// therefore we need to ensure that the rootElement is an ancestor of the current element
521-
rootElementDetected = isMatchingElement(parent, $rootElement);
522-
}
523-
524524
if (!bodyElementDetected) {
525525
// we also need to ensure that the element is or will be apart of the body element
526526
// otherwise it is pointless to even issue an animation to be rendered

test/ngAnimate/animateSpec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,33 @@ describe("animations", function() {
1010
dealoc(element);
1111
}));
1212

13+
it('should allow animations if the application is bootstrapped on the document node', function() {
14+
var capturedAnimation;
15+
16+
module(function($provide) {
17+
$provide.factory('$rootElement', function($document) {
18+
return $document;
19+
});
20+
$provide.factory('$$animation', function($$AnimateRunner) {
21+
return function() {
22+
capturedAnimation = arguments;
23+
return new $$AnimateRunner();
24+
};
25+
});
26+
});
27+
28+
inject(function($animate, $rootScope, $document) {
29+
$animate.enabled(true);
30+
31+
element = jqLite('<div></div>');
32+
33+
$animate.enter(element, jqLite($document[0].body));
34+
$rootScope.$digest();
35+
36+
expect(capturedAnimation).toBeTruthy();
37+
});
38+
});
39+
1340
describe('during bootstrap', function() {
1441
it('should be enabled only after the first digest is fired and the postDigest queue is empty',
1542
inject(function($animate, $rootScope) {

0 commit comments

Comments
 (0)