diff --git a/lib/core_dom/block_factory.dart b/lib/core_dom/block_factory.dart index ba006da4e..982f804ed 100644 --- a/lib/core_dom/block_factory.dart +++ b/lib/core_dom/block_factory.dart @@ -120,7 +120,7 @@ class BlockFactory { NgAnnotation annotation = ref.annotation; var visibility = _elementOnly; if (ref.annotation is NgController) { - scope = scope.createChild({}); + scope = scope.createChild(new PrototypeMap(scope.context)); nodeModule.value(Scope, scope); } if (ref.annotation.visibility == NgDirective.CHILDREN_VISIBILITY) { diff --git a/test/core_dom/compiler_spec.dart b/test/core_dom/compiler_spec.dart index 7fe0b8a9b..53c8c5805 100644 --- a/test/core_dom/compiler_spec.dart +++ b/test/core_dom/compiler_spec.dart @@ -19,7 +19,9 @@ main() => describe('dte.compiler', () { ..type(LocalAttrDirective) ..type(OneOfTwoDirectives) ..type(TwoOfTwoDirectives) - ..type(MyController); + ..type(MyController) + ..type(MyParentController) + ..type(MyChildController); return (Injector _injector) { injector = _injector; $compile = injector.get(Compiler); @@ -541,6 +543,17 @@ main() => describe('dte.compiler', () { rootScope.apply(); expect(log.result()).toEqual('IncludeTransclude; SimpleTransclude'); }))); + + it('should expose a parent controller to the scope of its children', inject((TestBed _) { + + var element = _.compile('
' + + '
{{ my_parent.data() }}
' + + '
'); + + rootScope.apply(); + + expect(element.text).toContain('my data'); + })); }); @@ -557,6 +570,22 @@ main() => describe('dte.compiler', () { }); +@NgController( + selector: '[my-parent-controller]', + publishAs: 'my_parent' +) +class MyParentController { + data() { + return "my data"; + } +} + +@NgController( + selector: '[my-child-controller]', + publishAs: 'my_child' +) +class MyChildController {} + @NgComponent( selector: 'tab', visibility: NgDirective.DIRECT_CHILDREN_VISIBILITY) diff --git a/test/directive/ng_a_spec.dart b/test/directive/ng_a_spec.dart index 5a8fd0fb6..0612495ec 100644 --- a/test/directive/ng_a_spec.dart +++ b/test/directive/ng_a_spec.dart @@ -37,7 +37,6 @@ main() { expect(_.rootScope.context['event'] is dom.UIEvent).toEqual(true); window.location.href = '#'; _.rootScope.context['url'] = '#url'; - print(_.rootElement.outerHtml); _.rootScope.apply(); _.triggerEvent(_.rootElement, 'click', 'MouseEvent'); expect(window.location.href.endsWith("#url")).toEqual(true);