Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 6142319

Browse files
committed
fix(compiler): Support camelCase property bindings
Fixes #1460
1 parent 94c3522 commit 6142319

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/core_dom/selector.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ class DirectiveSelector {
5757
});
5858
}
5959

60+
String _camelcase(String s) {
61+
var part = s.split('-').map((s) => s.toLowerCase());
62+
if (part.length <= 1)
63+
return part.join();
64+
return part.first + part.skip(1).map(capitalize).join();
65+
}
66+
6067
/**
6168
* [matchElement] returns an [ElementBinder] or a [TemplateElementBinder] configured with all the
6269
* directives triggered by the `node`.
@@ -92,7 +99,7 @@ class DirectiveSelector {
9299
if (attrName.startsWith("on-")) {
93100
builder.onEvents[attrName] = value;
94101
} else if (attrName.startsWith(BIND_PREFIX)) {
95-
builder.bindAttrs[attrName.substring(BIND_PREFIX_LENGTH)] =
102+
builder.bindAttrs[_camelcase(attrName.substring(BIND_PREFIX_LENGTH))] =
96103
_astParser(value, formatters: _formatters);
97104
}
98105

test/core_dom/web_components_spec.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,17 @@ main() {
7070

7171

7272
it('should bind to a non-existent property', () {
73+
registerElement('tests-empty', {});
74+
compileAndUpgrade('<tests-empty bind-newprop=27></tests-empty>');
75+
_.rootScope.apply();
76+
expect(customProp('newprop')).toEqual(27);
77+
});
78+
79+
it('should bind to a camelCase property', () {
7380
registerElement('tests-empty', {});
7481
compileAndUpgrade('<tests-empty bind-new-prop=27></tests-empty>');
7582
_.rootScope.apply();
76-
expect(customProp('new-prop')).toEqual(27);
83+
expect(customProp('newProp')).toEqual(27);
7784
});
7885

7986
it('should bind to both directives and properties', () {

0 commit comments

Comments
 (0)