親コントローラのコンテキストでgetDataInParentが呼び出される必要があります。親のコンテキストで親コントローラの関数を呼び出す
サンプル:
子ディレクティブが正しく親ディレクティブのテンプレートの中から、このような設定である:
:<child get-data="parentCtrl.getDataInParent"></child>
そして、ここでは私のコントローラの実装の簡単なモックアップ(getDataInParentのコメントを参照してください)
// *** parent controller
controller('parentController', [...., function(){
var that = this;
that.someData = ...;
that.getDataInParent = function(someArgs){
// Here I need to access "that.someData" and other
// properties/methods of this parent controller. But I can't!
// Because this method doesn't seemed to be called in the context of this controller.
};
};]
// *** child controller
controller('childController', [...., function(){
var that = this;
// Hooked up correctly and am able to call the parent's function like this:
var dataFromParent = $scope.getData().(someArgs);
};]
これは非常に一般的なシナリオのように多くの人が遭遇したと思われるので、私はまっすぐ進むべきであると期待しています。これのためのlutionは角度で。
私たちのディレクティブの宣言を表示します。一般的なアプローチは、関数を独立したスコープに渡すことです。新しいバージョンのangleでも 'bindToController'を使うことができます。問題を再現するデモを作成します。いつでも[mcve] – charlietfl
チャーリーを提供する必要があります、私はオンラインサンプルを作成しようとします。何が最高の場所でしょうか?プランカ? –
Plunker is very easyはい – charlietfl