次を使用して、AngularJSのイベントを2番目のコントローラーに発行しようとしています:
最初のコントローラー:
$scope.checkThemeContent = function(theme) {
console.log("Trying to get cards for theme id: " +theme.id);
console.log(theme);
$scope.selectedTheme = theme;
if(theme.count_of_cards >0) {
//$scope.$emit('detailDisplayed', {});
$scope.displayedTemplate = 'detail';
$rootScope.$emit('detailDisplayed', {});
} else {
$scope.displayedTemplate = 'empty';
}
};
2 番目のコントローラー:
$rootScope.$on('detailDisplayed', function(event, args) {
alert('Received');
$scope.initDataGrid();
});
しかし、イベントはトリガーされません。
スコープを逆方向に使用しようとしましたが、動作します。
どこに問題がありますか?
私はこのチュートリアルに従いました:
http://toddmotto.com/all-about-angulars-emit-broadcast-on-publish-subscribing/
助けてくれてありがとう。