2015-09-07 86 views
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}}' 
    } 
}); 

回答

4

角什麼內部將這個my-customer像代碼駝峯。
在這種情況下,多個-將轉換爲camelCase。
例:my-name-is-intekhab將被轉換爲myNameIsIntekhab

而且可以使用:data-

這是從角位點

歸一化處理如下:

地帶X-和來自元素/屬性前面的數據。
將:, - 或_分隔名稱轉換爲camelCase。