I would like to create a custom event in angularjs. The goal is that the event will be broadcast by a service and must be catched in a controller.
I have in my service :
function doSomething() {
// do something...
$rootScope.$broadcast("bced");
$rootScope.$emit("emitted");
console.log('event');
}
and my controller :
$rootScope.$on("bced",function(){
console.log("catched");
});
$rootScope.$on("emitted",function(){
console.log("catched");
});
$scope.$on("bced",function(){
console.log("catched");
});
$scope.$on("emitted",function(){
console.log("catched");
});
But I can't catch events in controller.
console.log('event') is shown but I can't catch any events.
Could someone explain me how to do that please?
$rootScope is correctly declared in the service and in the controller.