fix(compiler): elements with events only create binders but not protoElementInjectors.

Closes #577
This commit is contained in:
Rado Kirov 2015-02-10 14:43:59 -08:00
parent dd532fee72
commit 6e923cbf84
2 changed files with 31 additions and 6 deletions

View File

@ -98,7 +98,13 @@ export class ElementBinderBuilder extends CompileStep {
var elementBinder = null; var elementBinder = null;
if (current.hasBindings) { if (current.hasBindings) {
var protoView = current.inheritedProtoView; 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); current.componentDirective, current.templateDirective);
if (isPresent(current.textNodeBindings)) { if (isPresent(current.textNodeBindings)) {

View File

@ -26,7 +26,7 @@ export function main() {
var evalContext, view, changeDetector; var evalContext, view, changeDetector;
function createPipeline({textNodeBindings, propertyBindings, eventBindings, directives, protoElementInjector function createPipeline({textNodeBindings, propertyBindings, eventBindings, directives, protoElementInjector
}={}) { }={}) {
var reflector = new DirectiveMetadataReader(); var reflector = new DirectiveMetadataReader();
var parser = new Parser(new Lexer()); var parser = new Parser(new Lexer());
return new CompilePipeline([ return new CompilePipeline([
@ -52,9 +52,6 @@ export function main() {
}); });
hasBinding = true; hasBinding = true;
} }
if (isPresent(protoElementInjector)) {
current.inheritedProtoElementInjector = protoElementInjector;
}
if (isPresent(current.element.getAttribute('directives'))) { if (isPresent(current.element.getAttribute('directives'))) {
hasBinding = true; hasBinding = true;
for (var i=0; i<directives.length; i++) { for (var i=0; i<directives.length; i++) {
@ -66,6 +63,13 @@ export function main() {
current.hasBindings = true; current.hasBindings = true;
DOM.addClass(current.element, 'ng-binding'); DOM.addClass(current.element, 'ng-binding');
} }
if (isPresent(protoElementInjector) &&
(isPresent(current.element.getAttribute('text-binding')) ||
isPresent(current.element.getAttribute('prop-binding')) ||
isPresent(current.element.getAttribute('directives')) ||
isPresent(current.element.getAttribute('event-binding')))) {
current.inheritedProtoElementInjector = protoElementInjector;
}
if (isPresent(current.element.getAttribute('viewroot'))) { if (isPresent(current.element.getAttribute('viewroot'))) {
current.isViewRoot = true; current.isViewRoot = true;
current.inheritedProtoView = new ProtoView(current.element, current.inheritedProtoView = new ProtoView(current.element,
@ -114,13 +118,28 @@ export function main() {
var directives = [SomeDecoratorDirective]; var directives = [SomeDecoratorDirective];
var protoElementInjector = new ProtoElementInjector(null, 0, directives); var protoElementInjector = new ProtoElementInjector(null, 0, directives);
var pipeline = createPipeline({protoElementInjector: protoElementInjector, directives: directives}); var pipeline = createPipeline({protoElementInjector: protoElementInjector,
directives: directives});
var results = pipeline.process(el('<div viewroot directives></div>')); var results = pipeline.process(el('<div viewroot directives></div>'));
var pv = results[0].inheritedProtoView; var pv = results[0].inheritedProtoView;
expect(pv.elementBinders[0].protoElementInjector).toBe(protoElementInjector); 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('<div viewroot directives><div event-binding></div></div>'));
var pv = results[0].inheritedProtoView;
expect(pv.elementBinders[1].protoElementInjector).toBeNull();
});
it('should store the component directive', () => { it('should store the component directive', () => {
var directives = [SomeComponentDirective]; var directives = [SomeComponentDirective];
var pipeline = createPipeline({protoElementInjector: null, directives: directives}); var pipeline = createPipeline({protoElementInjector: null, directives: directives});