【发布时间】:2015-01-12 13:22:40
【问题描述】:
在 this plunker 上,您会注意到指令中属性名称模式 data-* 的奇怪行为。
电话:
<body ng-app="apptest" ng-controller="Controller">
Test of data named attribute :
<br/>
<directivetest data-test="vartest" test="vartest" another-test="vartest"></directivetest>
</body>
指令的:
angular.module('apptest', [])
.controller('Controller', ['$scope',
function($scope) {
$scope.vartest = "This is a test";
}
])
.directive('directivetest', function() {
return {
restrict: 'E',
scope: {
dataTest: '=',
test: '=',
anotherTest: '='
},
templateUrl: "directive.html"
}
});
将考虑 directivetest 的所有属性,但 data-test 并因此显示:
Test of data named attribute : Attribute with data-* name : Attribute with regular name : This is a test Attribute with an other regular name : This is a test
我想知道为什么会发生这种情况(我浪费了 4 个小时才发现这是问题所在)。
似乎不可能将指令命名为data-*,这是为什么呢?
我在这里http://www.w3schools.com/tags/att_global_data.asp 读到了一些关于它的内容,这就是我的属性未定义的原因吗?浏览器根本不读取?
【问题讨论】:
标签: javascript html angularjs