mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-09 17:10:34 +08:00
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:
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user