HTML element attribute names with hyphens are auto-converted to camelcase

孤街浪徒 提交于 2019-12-10 15:57:30

问题


I'm building a custom AngularJS directive to create a google map, and I've stored some of the google map options in custom attributes within my tag:

<googlemap zoom-control="true" …></googlemap>

Angular's directive compile method has parameters (tElement, tAttrs, transclude); when I log tAttrs to the console, the object has properties with names that have converted hyphens to camelCase:

Who is doing this—Angular or the browser (checked in Firefox & Chrome)? Can I rely on this behaviour?

P.S. When I check the DOM, the attributes of the html element still have hyphens.


回答1:


Angular is doing it. Yes you can rely on it:

From the Attributes page:

A shared object between directive compile / linking functions which contains normalized DOM element attributes. The the values reflect current binding state {{ }}. The normalization is needed since all of these are treated as equivalent in Angular:
<span ng:bind="a" ng-bind="a" data-ng-bind="a" x-ng-bind="a">



来源:https://stackoverflow.com/questions/14289459/html-element-attribute-names-with-hyphens-are-auto-converted-to-camelcase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!