带有指令的 HTML 视图:
<div click aaa="aaa()" action="action"></div>
控制器:我喜欢在 $scope.action 中传递函数 bbb():
app.controller('MainCtrl', function($scope) {
$scope.aaa = function () { alert('aaa'); }
$scope.bbb = function () { alert('bbb'); }
$scope.action = 'bbb()';
});
指示:
app.directive('click', function () {
return {
scope: {
aaa: '&',
action: '&'
},
template:
'<button ng-click="aaa()">show aaa (work ok)</button>' +
'<button ng-click="action">show bbb (not work)</button>' +
'<br>How to pass ng-click action in variable into directive?'
}
});
我不知道如何评估action
以替换为bbb()
.
这是 plunker:http ://plnkr.co/edit/d8DtsNARKPPJwk2SO2WJ