diff --git a/modules/angular2/src/core/compiler/pipeline/element_binder_builder.js b/modules/angular2/src/core/compiler/pipeline/element_binder_builder.js index 1cc496c058..90298c39e9 100644 --- a/modules/angular2/src/core/compiler/pipeline/element_binder_builder.js +++ b/modules/angular2/src/core/compiler/pipeline/element_binder_builder.js @@ -91,26 +91,12 @@ function roleSetter(element, value) { } } -// special mapping for cases where attribute name doesn't match property name -var _lazyAttrToProp; - -function attrToProp() { - if (!isPresent(_lazyAttrToProp)) { - _lazyAttrToProp = StringMapWrapper.merge({ - "inner-html": "innerHTML", - "readonly": "readOnly", - "tabindex": "tabIndex", - }, DOM.attrToPropMap); - } - return _lazyAttrToProp; -} - // tells if an attribute is handled by the ElementBinderBuilder step export function isSpecialProperty(propName:string) { return StringWrapper.startsWith(propName, ARIA_PREFIX) || StringWrapper.startsWith(propName, CLASS_PREFIX) || StringWrapper.startsWith(propName, STYLE_PREFIX) - || StringMapWrapper.contains(attrToProp(), propName); + || StringMapWrapper.contains(DOM.attrToPropMap, propName); } /** @@ -257,7 +243,7 @@ export class ElementBinderBuilder extends CompileStep { } _resolvePropertyName(attrName:string) { - var mappedPropName = StringMapWrapper.get(attrToProp(), attrName); + var mappedPropName = StringMapWrapper.get(DOM.attrToPropMap, attrName); return isPresent(mappedPropName) ? mappedPropName : attrName; } } diff --git a/modules/angular2/src/dom/browser_adapter.dart b/modules/angular2/src/dom/browser_adapter.dart index aead6a1327..ddc5dab47b 100644 --- a/modules/angular2/src/dom/browser_adapter.dart +++ b/modules/angular2/src/dom/browser_adapter.dart @@ -18,10 +18,11 @@ class BrowserDomAdapter extends DomAdapter { setRootDomAdapter(new BrowserDomAdapter()); } - // override JS logic of attribute to property mapping @override final attrToPropMap = const { - "inner-html": "innerHtml" + 'inner-html': 'innerHtml', + 'readonly': 'readOnly', + 'tabindex': 'tabIndex', }; query(String selector) => document.querySelector(selector); @@ -108,13 +109,13 @@ class BrowserDomAdapter extends DomAdapter { createScriptTag(String attrName, String attrValue, [HtmlDocument doc = null]) { if (doc == null) doc = document; - var el = doc.createElement("SCRIPT"); + var el = doc.createElement('SCRIPT'); el.setAttribute(attrName, attrValue); return el; } StyleElement createStyleElement(String css, [HtmlDocument doc = null]) { if (doc == null) doc = document; - var el = doc.createElement("STYLE"); + var el = doc.createElement('STYLE'); el.text = css; return el; } diff --git a/modules/angular2/src/dom/browser_adapter.es6 b/modules/angular2/src/dom/browser_adapter.es6 index cc18096b11..df90785ec0 100644 --- a/modules/angular2/src/dom/browser_adapter.es6 +++ b/modules/angular2/src/dom/browser_adapter.es6 @@ -2,15 +2,19 @@ import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection'; import {isPresent} from 'angular2/src/facade/lang'; import {DomAdapter, setRootDomAdapter} from './dom_adapter'; -var EMPTY_MAP = MapWrapper.create(); +var _attrToPropMap = { + 'inner-html': 'innerHTML', + 'readonly': 'readOnly', + 'tabindex': 'tabIndex', +}; export class BrowserDomAdapter extends DomAdapter { static makeCurrent() { setRootDomAdapter(new BrowserDomAdapter()); } - get attrToPropMap():Map { - return EMPTY_MAP + get attrToPropMap() { + return _attrToPropMap; } query(selector) { @@ -75,7 +79,7 @@ export class BrowserDomAdapter extends DomAdapter { return res; } clearNodes(el) { - el.innerHTML = ""; + el.innerHTML = ''; } appendChild(el, node) { el.appendChild(node); @@ -133,7 +137,7 @@ export class BrowserDomAdapter extends DomAdapter { return doc.createTextNode(text); } createScriptTag(attrName:string, attrValue:string, doc=document) { - var el = doc.createElement("SCRIPT"); + var el = doc.createElement('SCRIPT'); el.setAttribute(attrName, attrValue); return el; } diff --git a/modules/angular2/src/dom/dom_adapter.js b/modules/angular2/src/dom/dom_adapter.js index bf4adb9729..70e1a2668c 100644 --- a/modules/angular2/src/dom/dom_adapter.js +++ b/modules/angular2/src/dom/dom_adapter.js @@ -15,9 +15,15 @@ function _abstract() { */ @ABSTRACT() export class DomAdapter { - get attrToPropMap():Map { + + /** + * Maps attribute names to their corresponding property names for cases + * where attribute name doesn't match property name. + */ + get attrToPropMap() { throw _abstract(); } + parse(templateHtml:string) { throw _abstract(); }