2015-11-07 44 views
0
<html> 
<head> 
<title> 
</title> 
<script src="../../angular.min.js"></script> 
<script type="text/javascript"> 
    myApp = angular.module('myApp', []); 

    myApp.controller("empController", function($scope){ 
     $scope.ename = {nm : "Harry"}; 
     $scope.changeName = function(){$scope.ename.nm = "Ron";}; 
    }); 
    myApp.directive("empDirective", function(){ 
     return { 
      scope : {employeeName : "=myEmpName", nameChange : "&click"}, 
      template : 'Employee Name is {{employeeName.nm}}. <button ng-click="nameChange()">Change Name</button>' 
     }; 
    }); 

</script> 
</head> 

<body ng-app="myApp"> 

    <div ng-controller="empController"> 
     <div emp-directive myEmpName="ename" click="changeName()" > </div> 
     {{ename.nm}} 
    </div> 

</body> 

不能進去指令

的=本地範圍值當我運行上面的代碼,我沒有得到的內部指令的employeeName.nm值。不知道我錯過了什麼。我在AngularJS

回答

2

在模板的新,改

myEmpName 

my-emp-name 

角需要連字符模板分離屬性,並將它們轉換通過一個稱爲規範化的過程駱駝案件本身。

+0

不,問題!另外,如果你發現它是正確的,你能接受答案嗎? :) –