Reputation:
When I try to broadcast an event:
$scope.selectCategory = function(cat) {
$scope.$broadcast('Cat', {catID: cat});
}
it doesn't get caught by $scope.$on
:
$scope.$on('Cat', function (event, args) {
console.log("in");
$scope.catid = args.catID;
});
Question: I successfully pass the variable into broadcast but $scope.on callback never gets triggered.
Upvotes: 0
Views: 58
Reputation: 300
you need to $broadcast on $rootScope:
$scope.selectCategory = function(cat) {
// $location.path('/films/' + cat);
$rootScope.$broadcast('Cat', {catID: cat});
console.log(cat);
}
rest of your code should be fine then.
Upvotes: 1