From c914cd99b3aaf932e3c0e2a585eead7b76621f1b Mon Sep 17 00:00:00 2001 From: Stanislav Sysoev Date: Fri, 14 Feb 2014 15:11:58 +0400 Subject: fix(ngAnimate): TypeError Cannot call method 'querySelectorAll' in cancelChildAnimations When an element containing both ng-repeat and ng-if directives attempts to remove any items from the repeat collection, the following error is thrown: "TypeError Cannot call method 'querySelectorAll' of undefined". This happens because the cancelChildAnimations code naively belives that the jqLite object always has an element node within it. The fix in this commit addresses to securely check to see if a node was properly extracted before any child elements are inspected. Closes #6205 --- src/ngAnimate/animate.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/ngAnimate') diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js index 6b1eedfc..0e5fda98 100644 --- a/src/ngAnimate/animate.js +++ b/src/ngAnimate/animate.js @@ -942,16 +942,21 @@ angular.module('ngAnimate', ['ng']) function cancelChildAnimations(element) { var node = extractElementNode(element); - forEach(node.querySelectorAll('.' + NG_ANIMATE_CLASS_NAME), function(element) { - element = angular.element(element); - var data = element.data(NG_ANIMATE_STATE); - if(data && data.active) { - angular.forEach(data.active, function(operation) { - (operation.done || noop)(true); - cancelAnimations(operation.animations); - }); - } - }); + if (node) { + var nodes = angular.isFunction(node.getElementsByClassName) ? + node.getElementsByClassName(NG_ANIMATE_CLASS_NAME) : + node.querySelectorAll('.' + NG_ANIMATE_CLASS_NAME); + forEach(nodes, function(element) { + element = angular.element(element); + var data = element.data(NG_ANIMATE_STATE); + if(data && data.active) { + angular.forEach(data.active, function(operation) { + (operation.done || noop)(true); + cancelAnimations(operation.animations); + }); + } + }); + } } function cancelAnimations(animations) { -- cgit v1.2.3