fix(compiler): detect and strip data- prefix from bindings

Fixes #2687

Closes #2719
This commit is contained in:
Pawel Kozlowski
2015-06-23 19:07:09 +02:00
parent e69af1a3cd
commit cd65fc2a5e
2 changed files with 55 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import {isPresent, RegExpWrapper} from 'angular2/src/facade/lang';
import {isPresent, RegExpWrapper, StringWrapper} from 'angular2/src/facade/lang';
import {MapWrapper} from 'angular2/src/facade/collection';
import {Parser} from 'angular2/change_detection';
@ -30,6 +30,9 @@ export class PropertyBindingParser implements CompileStep {
var newAttrs = new Map();
MapWrapper.forEach(attrs, (attrValue, attrName) => {
attrName = this._normalizeAttributeName(attrName);
var bindParts = RegExpWrapper.firstMatch(BIND_NAME_REGEXP, attrName);
if (isPresent(bindParts)) {
if (isPresent(bindParts[1])) { // match: bind-prop
@ -69,6 +72,11 @@ export class PropertyBindingParser implements CompileStep {
MapWrapper.forEach(newAttrs, (attrValue, attrName) => { attrs.set(attrName, attrValue); });
}
_normalizeAttributeName(attrName: string): string {
return StringWrapper.startsWith(attrName, 'data-') ? StringWrapper.substring(attrName, 5) :
attrName;
}
_bindVariable(identifier, value, current: CompileElement, newAttrs: Map<any, any>) {
current.bindElement().bindVariable(dashCaseToCamelCase(identifier), value);
newAttrs.set(identifier, value);