请问如何在directive里面调用controller的function?代码如下:
var app = angular.module('myApp',[]);
app.controller('myCtrl',function($scope){
$scope.test= function(){
...
}
}
app.directive('myDir',
function(){
return {
restrict:'EA',
replace: true,
template: '<input ng-click="test()"></input>',
scope:{
test: '&'
},
controller: [
'$scope', function ($scope) {
$scope.accept = function () {
$scope.test();
};
}
],
}
}
);
html是这样的:<button type="button" ng-click="accept()">test</button>
要怎样才能实现点击test button的时候在调用了directive里的accept function之后同时调用controller里面的test function呢?
你看看可不可以这样子弄