Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
feat(ng-repeat): set the "$parent" variable to the parent context
Browse files Browse the repository at this point in the history
fixes #953
  • Loading branch information
vicb authored and rkirov committed Dec 16, 2014
1 parent d658909 commit 9da6d2e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/directive/ng_repeat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ class NgRepeat {
changeFunctions[addition.currentIndex] = (index, previousView) {
var childScope = _scope.createProtoChild();
var childContext = _updateContext(childScope.context, index, length)
..[_valueIdentifier] = value;
..[_valueIdentifier] = value
..[r'$parent'] = _scope.context;
var view = views[index] = _boundViewFactory(childScope);
_viewPort.insert(view, insertAfter: previousView);
};
Expand Down
14 changes: 14 additions & 0 deletions test/directive/ng_repeat_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ main() {
expect(element).toHaveText('ab');
});

it(r'should support $parent to access the parent context',
(Scope scope, Compiler compiler, Injector injector) {
var element = es('<div>'
'<span ng-repeat="list in lists">'
r'<span ng-repeat="i in list">{{$parent.$index}}-{{$index}},</span>'
'</span>'
'</div>');
ViewFactory viewFactory = compiler(element, directives);
View view = viewFactory(scope, null, element);
scope.context['lists'] = [[0, 0, 0], [0]];
scope.apply();
expect(element).toHaveText('0-0,0-1,0-2,1-0,');
});


it(r'should set create a list of items', (Scope scope, Compiler compiler, Injector injector) {
scope.context['items'] = [];
Expand Down

0 comments on commit 9da6d2e

Please sign in to comment.