1) If your controllers are parent-child, and you're emitting the event from the child controller, you just need to $emit the event and the parent controller just uses $on to listen to it.
Emitting event from child controller:
$scope.SaveDB(iObj,function(iResult){
$scope.$emit('saveCallback',iResult); //pass the data as the second parameter
});
Listening to the event (in parent controller):
$scope.$on('saveCallback',function(event,iResult){//receive the data as second parameter
});
2) If your controllers are siblings
From your controller, you $emit
the event to the parent's scope.
$scope.SaveDB(iObj,function(iResult){
$scope.$emit('saveCallback',iResult);
});
Your parent's scope then listens to this event and $broadcast
it to its children. This method could be written inside angular module's .run
block
$scope.$on('saveCallback',function (event,iresult){
$scope.$broadcast('saveCallback',iresult);
});
Or you can inject the $rootScope to the controller and have it $broadcast the event:
$scope.SaveDB(iObj,function(iResult){
$rootScope.$broadcast('saveCallback',iResult);
});
The scopes interested in the event can subscribe to it:
$scope.$on('saveCallBack',function(event, data) {
//access data here
});