Skip to content

Commit 8c2747b

Browse files
committed
fix(ngAnimateChildren): allow it to work on ngIf
Previously, ngAnimateChildren would set the data on the element in an $observe listener. This is too late when the element is animated immediately after compilation, as happens with ngIf Closes angular#13865
1 parent 0dfc1df commit 8c2747b

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed
+15-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
'use strict';
22

3-
var $$AnimateChildrenDirective = [function() {
4-
return function(scope, element, attrs) {
5-
var val = attrs.ngAnimateChildren;
6-
if (angular.isString(val) && val.length === 0) { //empty attribute
7-
element.data(NG_ANIMATE_CHILDREN_DATA, true);
8-
} else {
9-
attrs.$observe('ngAnimateChildren', function(value) {
3+
var $$AnimateChildrenDirective = ['$interpolate', function($interpolate) {
4+
return {
5+
link: function(scope, element, attrs) {
6+
var val = attrs.ngAnimateChildren;
7+
if (angular.isString(val) && val.length === 0) { //empty attribute
8+
element.data(NG_ANIMATE_CHILDREN_DATA, true);
9+
} else {
10+
// Interpolate and set the value, so that it is available to
11+
// animations that run right after compilation
12+
setData($interpolate(attrs.ngAnimateChildren)(scope));
13+
attrs.$observe('ngAnimateChildren', setData);
14+
}
15+
16+
function setData(value) {
1017
value = value === 'on' || value === 'true';
1118
element.data(NG_ANIMATE_CHILDREN_DATA, value);
12-
});
19+
}
1320
}
1421
};
1522
}];

test/ngAnimate/animateSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,22 @@ describe("animations", function() {
14921492
dealoc(element);
14931493
dealoc(child);
14941494
}));
1495+
1496+
it('should respect the value if the directive is on an element with ngIf',
1497+
inject(function($animate, $rootScope, $rootElement, $compile) {
1498+
1499+
parent.attr('ng-animate-children', 'true');
1500+
parent.attr('ng-if', 'true');
1501+
element.attr('ng-if', 'true');
1502+
1503+
$rootElement.append(parent);
1504+
parent.append(element);
1505+
1506+
$compile(parent)($rootScope);
1507+
$rootScope.$digest();
1508+
1509+
expect(captureLog.length).toBe(2);
1510+
}));
14951511
});
14961512

14971513
describe('.pin()', function() {

0 commit comments

Comments
 (0)