[英]AngularJS : Weird custom directive
I newbie to AngularJS .I have created my first custom directive with name of name my-customer
by copying from side and paste it in my working file. 我是AngularJS的新手。我通过从侧面复制并将其粘贴到我的工作文件中,创建了我的第一个名称为my-customer
的自定义指令。 When i try to built it myself i saw weird behavior because if I tried to access directive in with my-customer
it displays nothing on screen. 当我尝试自己构建它时,我看到了奇怪的行为,因为如果我尝试使用my-customer
访问指令,它就不会在屏幕上显示任何内容。
test.directive('my-customer',function(){
code...
}
when I saw the original example ,author access the same directive with myCustomer
name. 当我看到原始示例时,作者使用myCustomer
名称访问相同的指令。 How angular convert an html attribute to directive name . 如何将html属性的角度转换为指令名称。 because if I tried to use mycustomer
it still find nothing. 因为如果我试图使用mycustomer
它仍然没有找到任何东西。 What about controller which have more then one -
in their name like my-customer-a
怎么样的控制器有多个-
在他们的名字像my-customer-a
<div ng-app="myapp">
<div ng-controller="Controller">
<div id="test" my-customer></div>
</div>
</div>
var test = angular.module('myapp', [])
.controller('Controller', ['$scope', function($scope) {
$scope.customer = {
name: 'Naomi',
address: '1600 Amphitheatre'
};
}]);
test.directive('myCustomer',function(){
return{
template:'Name :{{customer.name}} Address: {{customer.address}}'
}
});
Angular internally converts this my-customer
like code to camelCase. Angular在内部将my-customer
代码转换为camelCase。
In this case of multiple -
will get converted to camelCase. 在这种情况下多次-
将转换为camelCase。
Ex: my-name-is-intekhab
will be converted to myNameIsIntekhab
例如: my-name-is-intekhab
将转换为myNameIsIntekhab
Also you can use :
or data-
您也可以使用:
或data-
This is from Angular site 这是来自Angular网站
The normalization process is as follows: 规范化过程如下:
Strip x- and data- from the front of the element/attributes. 从元素/属性的前面剥离x-和数据。
Convert the :, -, or _-delimited name to camelCase. 将:, - 或_分隔的名称转换为camelCase。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.