ディレクティブコントローラーを探しているようです。ディレクティブのパラメーターを使用してrequire:
、別のディレクティブのコントローラーをプルできます。次のようになります。
app.directive('foo', function() {
return {
restrict: 'A',
controller: function() {
this.qux = function() {
console.log("I'm from foo!");
};
},
link: function(scope, element, attrs) {
}
};
});
app.directive('bar', function() {
return {
restrict: 'A',
require: '^foo',
link: function(scope, element, attrs, foo) {
foo.qux();
}
};
});
angular docs から、require で使用できるシンボルとその機能を以下に示します。
(no prefix) - Locate the required controller on the current element.
? - Attempt to locate the required controller, or return null if not found.
^ - Locate the required controller by searching the element's parents.
?^ - Attempt to locate the required controller by searching the element's parents, or return null if not found.
これが私の例のjsbinです。http://jsbin.com/aLikEF/1/edit
必要に応じて機能する可能性のある別のオプションは、各ディレクティブが監視を設定して操作できるサービスを用意することです。たとえば、directive1 はサービス内のプロパティを監視し、変更に応答し、そのプロパティを変更できるボタンを設定することもできます。次に、directive2 もサービスを監視して変更することができ、どのように設定しても相互に応答します。その jsbin も必要な場合は、お知らせください。
これが役立つことを願っています!