fix($compile): set the iteration state before linking

This issue was introduced in b87e5fc092.
The state for each row has to be set up *before* linking.

The cloneFn (the function passed into $transclude) is called *before* actual linking and thus it is enough to update the state inside the cloneFn callback.
This commit is contained in:
Vojta Jina
2014-05-27 15:02:54 -07:00
parent 2ee29c5da8
commit 0c8a2cd2da
2 changed files with 17 additions and 1 deletions

View File

@@ -360,6 +360,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
$animate.move(getBlockElements(block.clone), null, jqLite(previousNode));
}
previousNode = getBlockEnd(block);
updateScope(block.scope, index);
} else {
// new item which we don't know about
$transclude(function(clone, scope) {
@@ -372,9 +373,9 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
// by a directive with templateUrl when it's template arrives.
block.clone = clone;
nextBlockMap[block.id] = block;
updateScope(block.scope, index);
});
}
updateScope(block.scope, index);
}
lastBlockMap = nextBlockMap;
});

View File

@@ -1195,6 +1195,21 @@ describe('ngRepeat and transcludes', function() {
});
});
it('should set the state before linking', function() {
module(function($compileProvider) {
$compileProvider.directive('assertA', valueFn(function(scope) {
// This linking function asserts that a is set.
// If we only test this by asserting binding, it will work even if the value is set later.
expect(scope.a).toBeDefined();
}));
});
inject(function($compile, $rootScope) {
var element = $compile('<div><span ng-repeat="a in [1]"><span assert-a></span></span></div>')($rootScope);
$rootScope.$digest();
dealoc(element);
});
});
});
describe('ngRepeat animations', function() {