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

Commit

Permalink
fix(ngAnimateChildren): make it compatible with ngIf
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Narretz committed Jan 28, 2016
1 parent 2072641 commit 8aecf46
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/ngAnimate/animateChildrenDirective.js
@@ -1,15 +1,22 @@
'use strict';

var $$AnimateChildrenDirective = [function() {
return function(scope, element, attrs) {
var val = attrs.ngAnimateChildren;
if (angular.isString(val) && val.length === 0) { //empty attribute
element.data(NG_ANIMATE_CHILDREN_DATA, true);
} else {
attrs.$observe('ngAnimateChildren', function(value) {
var $$AnimateChildrenDirective = ['$interpolate', function($interpolate) {
return {
link: function(scope, element, attrs) {
var val = attrs.ngAnimateChildren;
if (angular.isString(val) && val.length === 0) { //empty attribute
element.data(NG_ANIMATE_CHILDREN_DATA, true);
} else {
// Interpolate and set the value, so that it is available to
// animations that run right after compilation
setData($interpolate(attrs.ngAnimateChildren)(scope));
attrs.$observe('ngAnimateChildren', setData);
}

function setData(value) {
value = value === 'on' || value === 'true';
element.data(NG_ANIMATE_CHILDREN_DATA, value);
});
}
}
};
}];
16 changes: 16 additions & 0 deletions test/ngAnimate/animateSpec.js
Expand Up @@ -1492,6 +1492,22 @@ describe("animations", function() {
dealoc(element);
dealoc(child);
}));

it('should respect the value if the directive is on an element with ngIf',
inject(function($animate, $rootScope, $rootElement, $compile) {

parent.attr('ng-animate-children', 'true');
parent.attr('ng-if', 'true');
element.attr('ng-if', 'true');

$rootElement.append(parent);
parent.append(element);

$compile(parent)($rootScope);
$rootScope.$digest();

expect(captureLog.length).toBe(2);
}));
});

describe('.pin()', function() {
Expand Down

0 comments on commit 8aecf46

Please sign in to comment.