aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ngAnimate/animate.js25
-rw-r--r--test/ngAnimate/animateSpec.js16
2 files changed, 31 insertions, 10 deletions
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) {
diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js
index a30b5fe9..9179eb2b 100644
--- a/test/ngAnimate/animateSpec.js
+++ b/test/ngAnimate/animateSpec.js
@@ -3370,5 +3370,21 @@ describe("ngAnimate", function() {
expect(stat).toBe('gone');
});
});
+
+ it('should not throw an error when only comment nodes are rendered in the animation',
+ inject(function($rootScope, $compile) {
+
+ $rootScope.items = [1,2,3,4,5];
+
+ var element = html($compile('<div><div class="animated" ng-if="valid" ng-repeat="item in items"></div></div>')($rootScope));
+
+ $rootScope.$digest();
+
+ $rootScope.items = [];
+
+ $rootScope.$digest();
+
+ expect(element.children().length).toBe(0);
+ }));
});
});