diff --git a/modules/angular2/src/core/compiler/pipeline/element_binder_builder.js b/modules/angular2/src/core/compiler/pipeline/element_binder_builder.js index 99392cd715..6795efb13d 100644 --- a/modules/angular2/src/core/compiler/pipeline/element_binder_builder.js +++ b/modules/angular2/src/core/compiler/pipeline/element_binder_builder.js @@ -98,7 +98,13 @@ export class ElementBinderBuilder extends CompileStep { var elementBinder = null; if (current.hasBindings) { var protoView = current.inheritedProtoView; - elementBinder = protoView.bindElement(current.inheritedProtoElementInjector, + var protoInjectorWasBuilt = isBlank(parent) ? true : + current.inheritedProtoElementInjector !== parent.inheritedProtoElementInjector; + + var currentProtoElementInjector = protoInjectorWasBuilt ? + current.inheritedProtoElementInjector : null; + + elementBinder = protoView.bindElement(currentProtoElementInjector, current.componentDirective, current.templateDirective); if (isPresent(current.textNodeBindings)) { diff --git a/modules/angular2/test/core/compiler/pipeline/element_binder_builder_spec.js b/modules/angular2/test/core/compiler/pipeline/element_binder_builder_spec.js index 4339f16d2b..8687dce898 100644 --- a/modules/angular2/test/core/compiler/pipeline/element_binder_builder_spec.js +++ b/modules/angular2/test/core/compiler/pipeline/element_binder_builder_spec.js @@ -26,7 +26,7 @@ export function main() { var evalContext, view, changeDetector; function createPipeline({textNodeBindings, propertyBindings, eventBindings, directives, protoElementInjector - }={}) { + }={}) { var reflector = new DirectiveMetadataReader(); var parser = new Parser(new Lexer()); return new CompilePipeline([ @@ -52,9 +52,6 @@ export function main() { }); hasBinding = true; } - if (isPresent(protoElementInjector)) { - current.inheritedProtoElementInjector = protoElementInjector; - } if (isPresent(current.element.getAttribute('directives'))) { hasBinding = true; for (var i=0; i')); var pv = results[0].inheritedProtoView; expect(pv.elementBinders[0].protoElementInjector).toBe(protoElementInjector); }); + it('should not store the parent protoElementInjector', () => { + var directives = [SomeDecoratorDirective]; + var eventBindings = MapWrapper.createFromStringMap({ + 'event1': '1+1' + }); + + var pipeline = createPipeline({directives: directives, eventBindings: eventBindings}); + var results = pipeline.process(el('
')); + var pv = results[0].inheritedProtoView; + + expect(pv.elementBinders[1].protoElementInjector).toBeNull(); + }); + + it('should store the component directive', () => { var directives = [SomeComponentDirective]; var pipeline = createPipeline({protoElementInjector: null, directives: directives});