Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8aecf46

Browse files
committed
fix(ngAnimateChildren): make it compatible with ngIf
Previously, ngAnimateChildren would set the data on the element in an $observe listener, which means the data was available after one digest happend. This is too late when the element is animated immediately after compilation, as happens with ngIf. Now the data is also set right in the linking function. Fixes #13865 Closes #13876
1 parent 2072641 commit 8aecf46

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)