Skip to content

Instantly share code, notes, and snippets.

@jbro-io
Last active September 12, 2017 07:37
Show Gist options
  • Save jbro-io/7576616 to your computer and use it in GitHub Desktop.
Save jbro-io/7576616 to your computer and use it in GitHub Desktop.
Global event dispatcher/listener utility for AngularJS
angular.module('EventUtil', [])
.factory('broadcast', ['$rootScope', function($rootScope){
return function(eventName, payload){
$rootScope.$broadcast(eventName, payload);
};
}])
.factory('listen', ['$rootScope', function($rootScope){
return function(eventName, listener){
$rootScope.$on(eventName, listener);
};
}]);
@vance
Copy link

vance commented Sep 2, 2014

this is so trivial there's no reason for it to exist.

@renanreismartins
Copy link

It helped me. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment