Skip to content

Instantly share code, notes, and snippets.

@maximvl

maximvl/main.js

Forked from turtlemonvh/main.js
Created May 27, 2014
Embed
What would you like to do?
var MyApp = angular.module('MyApp');
MyApp.factory('msgBus', ['$rootScope', function($rootScope) {
var msgBus = {};
msgBus.emitMsg = function(msg, data) {
data = data || {};
$rootScope.$emit(msg, data);
};
msgBus.onMsg = function(msg, func, scope) {
var unbind = $rootScope.$on(msg, func);
if (scope) {
scope.$on('$destroy', unbind);
}
return unbind;
};
return msgBus;
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment