Skip to content

Commit 3bd0ade

Browse files
committed
fix(ngAnimate): allow animations if the body node is changed
If an ngIf is placed on the body then resulting node is different from what was there originally and that causes issues with ngAnimate. This patch fixes this. Closes angular#12366
1 parent 170cd96 commit 3bd0ade

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Diff for: src/ngAnimate/animateQueue.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
6666
return (nO.addClass && nO.addClass === cO.removeClass) || (nO.removeClass && nO.removeClass === cO.addClass);
6767
});
6868

69-
this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$body', '$$HashMap',
70-
'$$animation', '$$AnimateRunner', '$templateRequest', '$$jqLite', '$$forceReflow',
71-
function($$rAF, $rootScope, $rootElement, $document, $$body, $$HashMap,
72-
$$animation, $$AnimateRunner, $templateRequest, $$jqLite, $$forceReflow) {
69+
this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$HashMap', '$$animation',
70+
'$$AnimateRunner', '$templateRequest', '$$jqLite', '$$forceReflow',
71+
function($$rAF, $rootScope, $rootElement, $document, $$HashMap, $$animation,
72+
$$AnimateRunner, $templateRequest, $$jqLite, $$forceReflow) {
7373

7474
var activeAnimationsLookup = new $$HashMap();
7575
var disabledElementsLookup = new $$HashMap();
@@ -501,8 +501,17 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
501501
return getDomNode(nodeOrElmA) === getDomNode(nodeOrElmB);
502502
}
503503

504+
function isBodyElement(node, $document) {
505+
// if a ng-if is placed on the <body> tag then we
506+
// may end up with a new body element entirely so it's
507+
// best to just compare the body directly to the body
508+
// node present within the document node.
509+
return $document[0].body === node;
510+
}
511+
504512
function areAnimationsAllowed(element, parentElement, event) {
505-
var bodyElementDetected = isMatchingElement(element, $$body) || element[0].nodeName === 'HTML';
513+
var node = getDomNode(element);
514+
var bodyElementDetected = isBodyElement(node, $document) || node.nodeName === 'HTML';
506515
var rootElementDetected = isMatchingElement(element, $rootElement);
507516
var parentAnimationDetected = false;
508517
var animateChildren;
@@ -558,7 +567,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
558567
if (!bodyElementDetected) {
559568
// we also need to ensure that the element is or will be apart of the body element
560569
// otherwise it is pointless to even issue an animation to be rendered
561-
bodyElementDetected = isMatchingElement(parentElement, $$body);
570+
bodyElementDetected = isBodyElement(parentNode, $document);
562571
}
563572

564573
parentElement = parentElement.parent();

0 commit comments

Comments
 (0)