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

Commit 0c8a2cd

Browse files
committed
fix($compile): set the iteration state before linking
This issue was introduced in b87e5fc. 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.
1 parent 2ee29c5 commit 0c8a2cd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ng/directive/ngRepeat.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
360360
$animate.move(getBlockElements(block.clone), null, jqLite(previousNode));
361361
}
362362
previousNode = getBlockEnd(block);
363+
updateScope(block.scope, index);
363364
} else {
364365
// new item which we don't know about
365366
$transclude(function(clone, scope) {
@@ -372,9 +373,9 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
372373
// by a directive with templateUrl when it's template arrives.
373374
block.clone = clone;
374375
nextBlockMap[block.id] = block;
376+
updateScope(block.scope, index);
375377
});
376378
}
377-
updateScope(block.scope, index);
378379
}
379380
lastBlockMap = nextBlockMap;
380381
});

test/ng/directive/ngRepeatSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,21 @@ describe('ngRepeat and transcludes', function() {
11951195
});
11961196
});
11971197

1198+
1199+
it('should set the state before linking', function() {
1200+
module(function($compileProvider) {
1201+
$compileProvider.directive('assertA', valueFn(function(scope) {
1202+
// This linking function asserts that a is set.
1203+
// If we only test this by asserting binding, it will work even if the value is set later.
1204+
expect(scope.a).toBeDefined();
1205+
}));
1206+
});
1207+
inject(function($compile, $rootScope) {
1208+
var element = $compile('<div><span ng-repeat="a in [1]"><span assert-a></span></span></div>')($rootScope);
1209+
$rootScope.$digest();
1210+
dealoc(element);
1211+
});
1212+
});
11981213
});
11991214

12001215
describe('ngRepeat animations', function() {

0 commit comments

Comments
 (0)