3
我是AngularJS的新手。我創建了我的第一個名爲my-customer
的自定義指令,通過從側面複製並粘貼到我的工作文件中。當我嘗試自己構建它時,我看到了奇怪的行爲,因爲如果我嘗試訪問my-customer
中的指令,它將不會在屏幕上顯示任何內容。AngularJS:奇怪的自定義指令
test.directive('my-customer',function(){
code...
}
當我看到原來的例子,筆者訪問相同的指令與myCustomer
名。如何將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}}'
}
});