fix(ElementBinderBuilder): allow a directive to have mutliple bindings

fix #320
This commit is contained in:
Victor Berchet 2014-12-18 13:42:05 +01:00
parent 7027674081
commit 09092b269c
2 changed files with 24 additions and 3 deletions

View File

@ -122,13 +122,14 @@ export class ElementBinderBuilder extends CompileStep {
var isContentWatch = dirProp[len - 2] === '[' && dirProp[len - 1] === ']'; var isContentWatch = dirProp[len - 2] === '[' && dirProp[len - 1] === ']';
if (isContentWatch) dirBindingName = dirProp.substring(0, len - 2); if (isContentWatch) dirBindingName = dirProp.substring(0, len - 2);
protoView.bindDirectiveProperty( protoView.bindDirectiveProperty(
directiveIndex++, directiveIndex,
expression, expression,
dirBindingName, dirBindingName,
reflector.setter(dirBindingName), reflector.setter(dirBindingName),
isContentWatch isContentWatch
); );
}); });
directiveIndex++;
}); });
} }
} }

View File

@ -192,7 +192,9 @@ export function main() {
'boundprop2': 'prop2', 'boundprop2': 'prop2',
'boundprop3': 'prop3' 'boundprop3': 'prop3'
}); });
var directives = [SomeDecoratorDirectiveWithBinding, SomeTemplateDirectiveWithBinding, SomeComponentDirectiveWithBinding]; var directives = [SomeDecoratorDirectiveWith2Bindings,
SomeTemplateDirectiveWithBinding,
SomeComponentDirectiveWithBinding];
var protoElementInjector = new ProtoElementInjector(null, 0, directives, true); var protoElementInjector = new ProtoElementInjector(null, 0, directives, true);
var pipeline = createPipeline({ var pipeline = createPipeline({
propertyBindings: propertyBindings, propertyBindings: propertyBindings,
@ -210,7 +212,8 @@ export function main() {
evalContext.prop3 = 'c'; evalContext.prop3 = 'c';
changeDetector.detectChanges(); changeDetector.detectChanges();
expect(view.elementInjectors[0].get(SomeDecoratorDirectiveWithBinding).decorProp).toBe('a'); expect(view.elementInjectors[0].get(SomeDecoratorDirectiveWith2Bindings).decorProp).toBe('a');
expect(view.elementInjectors[0].get(SomeDecoratorDirectiveWith2Bindings).decorProp2).toBe('b');
expect(view.elementInjectors[0].get(SomeTemplateDirectiveWithBinding).templProp).toBe('b'); expect(view.elementInjectors[0].get(SomeTemplateDirectiveWithBinding).templProp).toBe('b');
expect(view.elementInjectors[0].get(SomeComponentDirectiveWithBinding).compProp).toBe('c'); expect(view.elementInjectors[0].get(SomeComponentDirectiveWithBinding).compProp).toBe('c');
}); });
@ -262,8 +265,25 @@ class SomeDecoratorDirective {
}) })
class SomeDecoratorDirectiveWithBinding { class SomeDecoratorDirectiveWithBinding {
decorProp; decorProp;
decorProp2;
constructor() { constructor() {
this.decorProp = null; this.decorProp = null;
this.decorProp2 = null;
}
}
@Decorator({
bind: {
'boundprop1': 'decorProp',
'boundprop2': 'decorProp2'
}
})
class SomeDecoratorDirectiveWith2Bindings {
decorProp;
decorProp2;
constructor() {
this.decorProp = null;
this.decorProp2 = null;
} }
} }