我有一个问题应该很简单,但我找不到答案。
我有控制器a:
app.controller('myController', function ($scope){
$scope.MyParentFunction = function(){
alert("it does not work..");
};
}
和控制器b,它在一个指令中:
app.directive('myDirective', function () {
var directive = {};
//properties
directive.scope = {
date: '=ngModel',
},
//controller
directive.controller = function ($scope) {
$scope.CallParentFunction = function(){
//Call Function From Parent scope here
$scope.MyParentFunction();
}
},
//call parent function in template
directive.template = '<div ng-click="CallParentFunction()">Call</div>';
return directive;
});
我如何调用&#34; MyParentFunction()&#34;从我的指令控制器? 提前谢谢!
答案 0 :(得分:1)
希望这会有所帮助:
您只需绑定父函数
即可directive.scope = {
date: '=ngModel',
callParentFunction: "&" //function binding
}
http://plnkr.co/edit/y7I1g7bKok8NOADipqX4?p=preview
看一下angularjs文档