Skip to content

Commit 09092b2

Browse files
committed
fix(ElementBinderBuilder): allow a directive to have mutliple bindings
fix angular#320
1 parent 7027674 commit 09092b2

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,14 @@ export class ElementBinderBuilder extends CompileStep {
122122
var isContentWatch = dirProp[len - 2] === '[' && dirProp[len - 1] === ']';
123123
if (isContentWatch) dirBindingName = dirProp.substring(0, len - 2);
124124
protoView.bindDirectiveProperty(
125-
directiveIndex++,
125+
directiveIndex,
126126
expression,
127127
dirBindingName,
128128
reflector.setter(dirBindingName),
129129
isContentWatch
130130
);
131131
});
132+
directiveIndex++;
132133
});
133134
}
134135
}

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ export function main() {
192192
'boundprop2': 'prop2',
193193
'boundprop3': 'prop3'
194194
});
195-
var directives = [SomeDecoratorDirectiveWithBinding, SomeTemplateDirectiveWithBinding, SomeComponentDirectiveWithBinding];
195+
var directives = [SomeDecoratorDirectiveWith2Bindings,
196+
SomeTemplateDirectiveWithBinding,
197+
SomeComponentDirectiveWithBinding];
196198
var protoElementInjector = new ProtoElementInjector(null, 0, directives, true);
197199
var pipeline = createPipeline({
198200
propertyBindings: propertyBindings,
@@ -210,7 +212,8 @@ export function main() {
210212
evalContext.prop3 = 'c';
211213
changeDetector.detectChanges();
212214

213-
expect(view.elementInjectors[0].get(SomeDecoratorDirectiveWithBinding).decorProp).toBe('a');
215+
expect(view.elementInjectors[0].get(SomeDecoratorDirectiveWith2Bindings).decorProp).toBe('a');
216+
expect(view.elementInjectors[0].get(SomeDecoratorDirectiveWith2Bindings).decorProp2).toBe('b');
214217
expect(view.elementInjectors[0].get(SomeTemplateDirectiveWithBinding).templProp).toBe('b');
215218
expect(view.elementInjectors[0].get(SomeComponentDirectiveWithBinding).compProp).toBe('c');
216219
});
@@ -262,8 +265,25 @@ class SomeDecoratorDirective {
262265
})
263266
class SomeDecoratorDirectiveWithBinding {
264267
decorProp;
268+
decorProp2;
265269
constructor() {
266270
this.decorProp = null;
271+
this.decorProp2 = null;
272+
}
273+
}
274+
275+
@Decorator({
276+
bind: {
277+
'boundprop1': 'decorProp',
278+
'boundprop2': 'decorProp2'
279+
}
280+
})
281+
class SomeDecoratorDirectiveWith2Bindings {
282+
decorProp;
283+
decorProp2;
284+
constructor() {
285+
this.decorProp = null;
286+
this.decorProp2 = null;
267287
}
268288
}
269289

0 commit comments

Comments
 (0)