diff --git a/modules/core/src/compiler/pipeline/proto_element_injector_builder.js b/modules/core/src/compiler/pipeline/proto_element_injector_builder.js index 5f8e7c6753..27dd7ffd21 100644 --- a/modules/core/src/compiler/pipeline/proto_element_injector_builder.js +++ b/modules/core/src/compiler/pipeline/proto_element_injector_builder.js @@ -49,13 +49,10 @@ export class ProtoElementInjectorBuilder extends CompileStep { } _getParentProtoElementInjector(parent, current) { - var parentProtoElementInjector = null; - if (current.isViewRoot) { - parentProtoElementInjector = null; - } else if (isPresent(parent)) { - parentProtoElementInjector = parent.inheritedProtoElementInjector; + if (isPresent(parent) && !current.isViewRoot) { + return parent.inheritedProtoElementInjector; } - return parentProtoElementInjector; + return null; } _collectDirectiveBindings(pipelineElement) { diff --git a/modules/core/src/compiler/view.js b/modules/core/src/compiler/view.js index 61c7fcd8f7..c479f269fd 100644 --- a/modules/core/src/compiler/view.js +++ b/modules/core/src/compiler/view.js @@ -309,9 +309,11 @@ export class ProtoView { // elementInjectors and rootElementInjectors var protoElementInjector = binder.protoElementInjector; if (isPresent(protoElementInjector)) { - var parentElementInjector = isPresent(protoElementInjector.parent) ? elementInjectors[protoElementInjector.parent.index] : null; - elementInjector = protoElementInjector.instantiate(parentElementInjector, hostElementInjector); - if (isBlank(parentElementInjector)) { + if (isPresent(protoElementInjector.parent)) { + var parentElementInjector = elementInjectors[protoElementInjector.parent.index]; + elementInjector = protoElementInjector.instantiate(parentElementInjector, null); + } else { + elementInjector = protoElementInjector.instantiate(null, hostElementInjector); ListWrapper.push(rootElementInjectors, elementInjector); } } diff --git a/modules/core/test/compiler/view_spec.js b/modules/core/test/compiler/view_spec.js index 2fd83354e9..257763647d 100644 --- a/modules/core/test/compiler/view_spec.js +++ b/modules/core/test/compiler/view_spec.js @@ -7,8 +7,9 @@ import {Component, Decorator, Template} from 'core/annotations/annotations'; import {OnChange} from 'core/core'; import {Lexer, Parser, ProtoRecordRange, ChangeDetector} from 'change_detection/change_detection'; import {TemplateConfig} from 'core/annotations/template_config'; +import {List} from 'facade/collection'; import {DOM, Element} from 'facade/dom'; -import {FIELD} from 'facade/lang'; +import {int} from 'facade/lang'; import {Injector} from 'di/di'; import {View} from 'core/compiler/view'; import {ViewPort} from 'core/compiler/viewport'; @@ -206,6 +207,36 @@ export function main() { expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true); expect(view.elementInjectors[1].parent).toBe(view.elementInjectors[0]); }); + + it('should not pass the host injector when a parent injector exists', () => { + var pv = new ProtoView(createElement('