2016-12-23 15 views
0

私は本当にシンプルなはずの質問がありますが、答えを見つけることができません。指令コントローラからの角度呼び出しコントローラの機能

私は、コントローラ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; 

}); 

は、どのように私は私のディレクティブコントローラから "MyParentFunction()" を呼び出すことができますか? ありがとうございます!これが役立つ

+0

があるangularjsのドキュメントを見てみましょうMyController内の 'MyDirective'をドーム構造? plunkerを作成することもできますか?http://plnkr.co/edit – dreamweiver

+0

次のものは動作しませんが、主なアイデアを示しています! http://plnkr.co/edit/dv90rBhtgXl9pOU12VKj?p=preview –

答えて

関連する問題