Skip to content

Commit 6e923cb

Browse files
committed
fix(compiler): elements with events only create binders but not protoElementInjectors.
Closes angular#577
1 parent dd532fe commit 6e923cb

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

modules/angular2/src/core/compiler/pipeline/element_binder_builder.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ export class ElementBinderBuilder extends CompileStep {
9898
var elementBinder = null;
9999
if (current.hasBindings) {
100100
var protoView = current.inheritedProtoView;
101-
elementBinder = protoView.bindElement(current.inheritedProtoElementInjector,
101+
var protoInjectorWasBuilt = isBlank(parent) ? true :
102+
current.inheritedProtoElementInjector !== parent.inheritedProtoElementInjector;
103+
104+
var currentProtoElementInjector = protoInjectorWasBuilt ?
105+
current.inheritedProtoElementInjector : null;
106+
107+
elementBinder = protoView.bindElement(currentProtoElementInjector,
102108
current.componentDirective, current.templateDirective);
103109

104110
if (isPresent(current.textNodeBindings)) {

modules/angular2/test/core/compiler/pipeline/element_binder_builder_spec.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function main() {
2626
var evalContext, view, changeDetector;
2727

2828
function createPipeline({textNodeBindings, propertyBindings, eventBindings, directives, protoElementInjector
29-
}={}) {
29+
}={}) {
3030
var reflector = new DirectiveMetadataReader();
3131
var parser = new Parser(new Lexer());
3232
return new CompilePipeline([
@@ -52,9 +52,6 @@ export function main() {
5252
});
5353
hasBinding = true;
5454
}
55-
if (isPresent(protoElementInjector)) {
56-
current.inheritedProtoElementInjector = protoElementInjector;
57-
}
5855
if (isPresent(current.element.getAttribute('directives'))) {
5956
hasBinding = true;
6057
for (var i=0; i<directives.length; i++) {
@@ -66,6 +63,13 @@ export function main() {
6663
current.hasBindings = true;
6764
DOM.addClass(current.element, 'ng-binding');
6865
}
66+
if (isPresent(protoElementInjector) &&
67+
(isPresent(current.element.getAttribute('text-binding')) ||
68+
isPresent(current.element.getAttribute('prop-binding')) ||
69+
isPresent(current.element.getAttribute('directives')) ||
70+
isPresent(current.element.getAttribute('event-binding')))) {
71+
current.inheritedProtoElementInjector = protoElementInjector;
72+
}
6973
if (isPresent(current.element.getAttribute('viewroot'))) {
7074
current.isViewRoot = true;
7175
current.inheritedProtoView = new ProtoView(current.element,
@@ -114,13 +118,28 @@ export function main() {
114118
var directives = [SomeDecoratorDirective];
115119
var protoElementInjector = new ProtoElementInjector(null, 0, directives);
116120

117-
var pipeline = createPipeline({protoElementInjector: protoElementInjector, directives: directives});
121+
var pipeline = createPipeline({protoElementInjector: protoElementInjector,
122+
directives: directives});
118123
var results = pipeline.process(el('<div viewroot directives></div>'));
119124
var pv = results[0].inheritedProtoView;
120125

121126
expect(pv.elementBinders[0].protoElementInjector).toBe(protoElementInjector);
122127
});
123128

129+
it('should not store the parent protoElementInjector', () => {
130+
var directives = [SomeDecoratorDirective];
131+
var eventBindings = MapWrapper.createFromStringMap({
132+
'event1': '1+1'
133+
});
134+
135+
var pipeline = createPipeline({directives: directives, eventBindings: eventBindings});
136+
var results = pipeline.process(el('<div viewroot directives><div event-binding></div></div>'));
137+
var pv = results[0].inheritedProtoView;
138+
139+
expect(pv.elementBinders[1].protoElementInjector).toBeNull();
140+
});
141+
142+
124143
it('should store the component directive', () => {
125144
var directives = [SomeComponentDirective];
126145
var pipeline = createPipeline({protoElementInjector: null, directives: directives});

0 commit comments

Comments
 (0)