我一直在這個特定的測試我的頭幾個小時。我相信所展示的指令應該可以工作,但我正在傳遞給隔離範圍的值未定義。AngularJS隔離範圍沒有被傳遞到指令
代碼:
HTML
<!doctype html>
<html ng-app="myApp">
<body>
<a ng-href="#" class="test-scope" name="test">Console should say 'test' but gives undefined</a>
</body>
</html>
的JavaScript
angular.module('myApp', [])
.directive('testScope', function() {
return {
restrict: 'C',
scope: {
name: "="
},
link: function(scope, element, attrs) {
console.log(scope.name);
}
};
});
這裏的小提琴:http://jsfiddle.net/jPtb3/8/
任何幫助將是AP preciated,我一定在做錯事。
改變你的小提琴,看 –