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

Commit cad8cc4

Browse files
matskomhevery
authored andcommitted
fix(compile): ensure parent controllers are exposed within the scope of their children
Closes #602
1 parent d7ecabd commit cad8cc4

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/core_dom/block_factory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class BlockFactory {
120120
NgAnnotation annotation = ref.annotation;
121121
var visibility = _elementOnly;
122122
if (ref.annotation is NgController) {
123-
scope = scope.createChild({});
123+
scope = scope.createChild(new PrototypeMap(scope.context));
124124
nodeModule.value(Scope, scope);
125125
}
126126
if (ref.annotation.visibility == NgDirective.CHILDREN_VISIBILITY) {

test/core_dom/compiler_spec.dart

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ main() => describe('dte.compiler', () {
1919
..type(LocalAttrDirective)
2020
..type(OneOfTwoDirectives)
2121
..type(TwoOfTwoDirectives)
22-
..type(MyController);
22+
..type(MyController)
23+
..type(MyParentController)
24+
..type(MyChildController);
2325
return (Injector _injector) {
2426
injector = _injector;
2527
$compile = injector.get(Compiler);
@@ -541,6 +543,17 @@ main() => describe('dte.compiler', () {
541543
rootScope.apply();
542544
expect(log.result()).toEqual('IncludeTransclude; SimpleTransclude');
543545
})));
546+
547+
it('should expose a parent controller to the scope of its children', inject((TestBed _) {
548+
549+
var element = _.compile('<div my-parent-controller>' +
550+
' <div my-child-controller>{{ my_parent.data() }}</div>' +
551+
'</div>');
552+
553+
rootScope.apply();
554+
555+
expect(element.text).toContain('my data');
556+
}));
544557
});
545558

546559

@@ -557,6 +570,22 @@ main() => describe('dte.compiler', () {
557570
});
558571

559572

573+
@NgController(
574+
selector: '[my-parent-controller]',
575+
publishAs: 'my_parent'
576+
)
577+
class MyParentController {
578+
data() {
579+
return "my data";
580+
}
581+
}
582+
583+
@NgController(
584+
selector: '[my-child-controller]',
585+
publishAs: 'my_child'
586+
)
587+
class MyChildController {}
588+
560589
@NgComponent(
561590
selector: 'tab',
562591
visibility: NgDirective.DIRECT_CHILDREN_VISIBILITY)

0 commit comments

Comments
 (0)