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

Commit 9da6d2e

Browse files
vicbrkirov
authored andcommitted
feat(ng-repeat): set the "$parent" variable to the parent context
fixes #953
1 parent d658909 commit 9da6d2e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/directive/ng_repeat.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ class NgRepeat {
173173
changeFunctions[addition.currentIndex] = (index, previousView) {
174174
var childScope = _scope.createProtoChild();
175175
var childContext = _updateContext(childScope.context, index, length)
176-
..[_valueIdentifier] = value;
176+
..[_valueIdentifier] = value
177+
..[r'$parent'] = _scope.context;
177178
var view = views[index] = _boundViewFactory(childScope);
178179
_viewPort.insert(view, insertAfter: previousView);
179180
};

test/directive/ng_repeat_spec.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ main() {
4141
expect(element).toHaveText('ab');
4242
});
4343

44+
it(r'should support $parent to access the parent context',
45+
(Scope scope, Compiler compiler, Injector injector) {
46+
var element = es('<div>'
47+
'<span ng-repeat="list in lists">'
48+
r'<span ng-repeat="i in list">{{$parent.$index}}-{{$index}},</span>'
49+
'</span>'
50+
'</div>');
51+
ViewFactory viewFactory = compiler(element, directives);
52+
View view = viewFactory(scope, null, element);
53+
scope.context['lists'] = [[0, 0, 0], [0]];
54+
scope.apply();
55+
expect(element).toHaveText('0-0,0-1,0-2,1-0,');
56+
});
57+
4458

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

0 commit comments

Comments
 (0)