本文介绍了为什么我不能用数据 - *作为指令的属性名称,JS角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在以下plunker你可以看到带有属性名称的模式在指令数据 - *一个奇怪的行为。
召唤:
<机身NG-应用=apptestNG控制器=控制器>
数据测试指定属性:
< BR />
< directivetest数据测试=vartest测试=vartest另一个测试=vartest>< / directivetest>
< /身体GT;
该指令:
angular.module('apptest',[])
.controller('控制',['$范围',
功能($范围){
$ scope.vartest =这是一个测试;
}
])
.directive('directivetest',函数(){
返回{
限制:'E',
范围: {
数据测试:'=',
试验:=,
anotherTest:'='
},
templateUrl:directive.html
}
});
将采取directivetest所有属性考虑,但数据的测试,因此显示:
I am wondering why this happens (I wasted 4 hours before I figured out that it was the issue).
It seems to be impossible to name a directive data-*, why is that?
I read something about it here http://www.w3schools.com/tags/att_global_data.asp, is it why my attribute is undefined? It is simply not read by the browser?
解决方案
The data-
prefixed forms of directive names allow HTML validators to work because custom data attributes in HTML 5 follow that form. AngularJS directive names are normalized as follows to support custom data attributes:
这篇关于为什么我不能用数据 - *作为指令的属性名称,JS角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!