1
我在angularjs中创建了一个指令。在link
我试图通过attrs
获得属性。他们都被正常化为驼峰形式。但我想重新插入到其他元素。所以我想将camelCased值转换为以短划线定界的值。即Denormalize
的值。角js有没有简单的方法来做到这一点。非规范化属性值 - 将驼峰值转换为以划线定界的值
module.directive('myDirective', function(){
return {
'link': function(scope, element, attr, controller){
....
var newElement = jQuery("<div></div>");
for(var key in attr){
newElement.attr(attr[key]); // !newElement will not keep dashes in attribute
// i.e. dashes will be removed from attributes
}
}
};
});
我可以正常化一个破折号分隔的值给camelCased的值,但是我应该怎么做才能使它们非规范化。
所以在这里我的实际问题是保留破折号属性