我正在尝试使用以下方法将 AngularJS 中的事件发送到第二个控制器:
第一控制器:
$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';
}
};
第二个控制器:
$rootScope.$on('detailDisplayed', function(event, args) {
alert('Received');
$scope.initDataGrid();
});
但是没有触发事件。
我尝试反向使用范围,它可以工作。
请问哪里有问题?
我遵循了本教程:
http://toddmotto.com/all-about-angulars-emit-broadcast-on-publish-subscribing/
谢谢你的帮助。