私はそのうちの一つが、このような別のものを得るためにメッセージをブロードキャストすることを2つのディレクティブがあります(demo)
angular.module('app', []);
angular.module('app').directive('foo',
function($rootScope) {
return {
restrict: 'EAC',
link: function($scope, element, attrs, controller) {
$rootScope.$on("onStart", function(e,d){
alert(d.message)
});
}
};
}
);
angular.module('app').directive('bar',
function($rootScope) {
return {
restrict: 'EAC',
link: function($scope, element, attrs, controller) {
$rootScope.$broadcast("onStart", {message: "start"});
}
};
}
);
このギーブスメッセージを。
私の指示のテンプレートURLが必要です。このように設定してください(demo)。
angular.module('app').directive('foo',
function($rootScope) {
return {
restrict: 'EAC',
templateUrl: "tpl.html",
link: function($scope, element, attrs, controller) {
$rootScope.$on("onStart", function(e,d){
alert(d.message)
});
}
};
}
);
ただし、現在アラートには入力されません。
の代わりに
template
を使用することができ、この問題のための任意の解決策はありますか? – bartelomaこれは間違っているようですが、 'onStart'リスナーの登録をfooディレクティブのreturn文の前に置くことができます。それはうまく動作しますが、非常にハッキーです。さらに、 'link'関数に渡すすべてのパラメータにアクセスすることはできません。 – gerrit