请问如何在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呢?
1 回答
拉风的咖菲猫
TA贡献1995条经验 获得超2个赞
var app = angular.module('myApp',[]);
app.controller('myCtrl',function($scope){
$scope.accept= function(){
...
}
}
app.directive('myDir',
function(){
return {
restrict:'EA',
replace: true,
template: '<input ng-click="test()"></input>',
scope:{
test: '&'
},
link: function(scope, element, attrs) {
元素.bind("click",function(){
scope.accept();
})
}
}
}
);
你看看可不可以这样子弄
添加回答
举报
0/150
提交
取消