fix(compiler): properly bind to properties that don't have matching attr name

Fixes #619
Closes #783
This commit is contained in:
Pawel Kozlowski
2015-02-25 15:30:37 +01:00
parent e490861ba2
commit 7e6f536cf5
5 changed files with 91 additions and 8 deletions

View File

@ -102,6 +102,41 @@ export function main() {
});
});
it('should consume binding to propery names where attr name and property name do not match', (done) => {
tplResolver.setTemplate(MyComp, new Template({inline: '<div [tabindex]="ctxNumProp"></div>'}));
compiler.compile(MyComp).then((pv) => {
createView(pv);
cd.detectChanges();
expect(view.nodes[0].tabIndex).toEqual(0);
ctx.ctxNumProp = 5;
cd.detectChanges();
expect(view.nodes[0].tabIndex).toEqual(5);
done();
});
});
it('should consume binding to inner-html', (done) => {
tplResolver.setTemplate(MyComp, new Template({inline: '<div inner-html="{{ctxProp}}"></div>'}));
compiler.compile(MyComp).then((pv) => {
createView(pv);
ctx.ctxProp = 'Some <span>HTML</span>';
cd.detectChanges();
expect(DOM.getInnerHTML(view.nodes[0])).toEqual('Some <span>HTML</span>');
ctx.ctxProp = 'Some other <div>HTML</div>';
cd.detectChanges();
expect(DOM.getInnerHTML(view.nodes[0])).toEqual('Some other <div>HTML</div>');
done();
});
});
it('should consume directive watch expression change.', (done) => {
var tpl =
'<div>' +
@ -490,8 +525,10 @@ class PushBasedComp {
@Component()
class MyComp {
ctxProp:string;
ctxNumProp;
constructor() {
this.ctxProp = 'initial value';
this.ctxNumProp = 0;
}
}

View File

@ -196,6 +196,27 @@ export function main() {
expect(view.nodes[0].hidden).toEqual(false);
});
it('should bind element properties where attr name and prop name do not match', () => {
var propertyBindings = MapWrapper.createFromStringMap({
'tabindex': 'prop1'
});
var pipeline = createPipeline({propertyBindings: propertyBindings});
var results = pipeline.process(el('<div viewroot prop-binding></div>'));
var pv = results[0].inheritedProtoView;
expect(pv.elementBinders[0].hasElementPropertyBindings).toBe(true);
instantiateView(pv);
evalContext.prop1 = 1;
changeDetector.detectChanges();
expect(view.nodes[0].tabIndex).toEqual(1);
evalContext.prop1 = 0;
changeDetector.detectChanges();
expect(view.nodes[0].tabIndex).toEqual(0);
});
it('should bind to aria-* attributes when exp evaluates to strings', () => {
var propertyBindings = MapWrapper.createFromStringMap({
'aria-label': 'prop1'