HTML元素属性带连字符的名称是自动转换为驼峰驼峰、转换为、字符、属性

2023-09-13 05:14:21 作者:我爱的人他已飞走了

我建立一个自定义的AngularJS指令来创建一个谷歌地图,我已经在我的自定义标签内存储的属性部分的谷歌地图选项:

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>

角的指令编译方法有参数(tElement,tAttrs,transclude);当我登录 tAttrs 到控制台,该对象已转换连字符驼峰与名称属性:

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:

谁在做这个角或浏览器(在Firefox和放大器检查;浏览器)?我可以依靠这种行为?

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

P.S。当我检查的DOM中,HTML元素的属性还是有连字符。

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

推荐答案

角是做什么的。是的,你可以依靠它:

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

从属性页:

一个共享对象的属性。该数值反映了当前绑定状态{{}}。需要正常化,因为所有这些都为等同于角处理:搜索    &LT;跨度NG:绑定=一个NG绑定=数据-NG-绑定=一个X-NG-绑定=一个&GT;

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">