angular 从指令控制器中调用控制器函数

angular calling controller function in from directive controller

我有一个应该很简单的问题,但我找不到答案。

我有一个控制器:

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;

});

如何从指令控制器调用 "MyParentFunction()"? 提前致谢!

希望这会有所帮助:

你只需要绑定你的父函数

directive.scope = {
    date: '=ngModel',
    callParentFunction: "&"  //function binding 
}

http://plnkr.co/edit/y7I1g7bKok8NOADipqX4?p=preview

查看 angularjs 文档

https://docs.angularjs.org/guide/directive