我在主控制器中定义了一个函数getData,我想在我的指令中使用它。我尝试在范围内包含该功能,但似乎我仍然缺少某些东西或做错了。
var app = angular.module('plunker', []);
app.directive("position", function(){
return {
restrict:'A',
template: "<tr><td ng-repeat='(key,value) in position'>{{getData(key,value,$index)}}</td></tr>",
replace: false,
scope: {
position: '=',
getData: '&'
}
};
});
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.positions = [{ Name: "Quarterback", Code: "QB" },
{ Name: "Wide Receiver", Code: "WR" }
];
$scope.getData=function(key , value,index){
return '|' + value + '|';
}
});