Javascript AngularJS:奇怪的自定义指令
我是AngularJS的新手。通过从侧面复制并粘贴到我的工作文件中,我创建了第一个名为nameJavascript AngularJS:奇怪的自定义指令,javascript,angularjs,angularjs-directive,directive,Javascript,Angularjs,Angularjs Directive,Directive,我是AngularJS的新手。通过从侧面复制并粘贴到我的工作文件中,我创建了第一个名为namemy customer的自定义指令。当我尝试自己构建它时,我看到了奇怪的行为,因为如果我尝试使用my customer访问中的指令,它在屏幕上不会显示任何内容 test.directive('my-customer',function(){ code... } 当我看到最初的示例时,作者使用myCustomername访问相同的指令。如何将html属性转换为指令名。 因为如果我尝试使用mycus
my customer
的自定义指令。当我尝试自己构建它时,我看到了奇怪的行为,因为如果我尝试使用my customer
访问中的指令,它在屏幕上不会显示任何内容
test.directive('my-customer',function(){
code...
}
当我看到最初的示例时,作者使用myCustomer
name访问相同的指令。如何将html属性转换为指令名。
因为如果我尝试使用mycustomer
它仍然找不到任何东西。如果控制器的名称中有多个-
,例如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}}'
}
});
var test=angular.module('myapp',[])
.controller('controller',['$scope',function($scope){
$scope.customer={
名字:“娜奥米”,
地址:“1600圆形剧场”
};
}]);
test.directive('myCustomer',function(){
返回{
模板:'Name:{{customer.Name}}地址:{{{customer.Address}}'
}
});
Angular内部将此我的客户
类似的代码转换为camelCase。在这种情况下,多个
-
将转换为camelCase。例如:
我的名字是intekhab
将转换为我的名字是intekhab
您还可以使用:
或数据-
这是从一个角度的网站
规范化过程如下所示:
从元素/属性的前面剥离x和数据。将以:、-或_分隔的名称转换为camelCase