我正在构建一个自定义的 AngularJS 指令来创建一个谷歌地图,我已经在我的标签中的自定义属性中存储了一些谷歌地图选项:
<googlemap zoom-control="true" …></googlemap>
Angular 的指令编译方法有参数(tElement, tAttrs, transclude)
;当我将 tAttrs
记录到控制台时,该对象的属性名称已将连字符转换为驼峰式:
谁在做这件事——Angular 还是浏览器(在 Firefox 和 Chrome 中检查过)?我可以依赖这种行为吗?
附言当我检查 DOM 时,html 元素的属性仍然有连字符。
最佳答案
Angular 正在做这件事。是的,您可以信赖它:
来自Attributes页:
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">
关于json - 带有连字符的 HTML 元素属性名称会自动转换为驼峰式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14289459/