Skip to content

Instantly share code, notes, and snippets.

@SimplGy
Last active August 29, 2015 13:57
Show Gist options
  • Save SimplGy/9610552 to your computer and use it in GitHub Desktop.
Save SimplGy/9610552 to your computer and use it in GitHub Desktop.
Angular decoration makes $rootScope an event bus that cleans up after itself automaticaly. From: https://github.com/angular/angular.js/issues/4574
$provide.decorator('$rootScope', ['$delegate', function($rootScope) {
$rootScope.prototype.$onRootScope = function(eventName, callback) {
var unbind = $rootScope.$on(eventName, callback);
this.$on('$destroy', unbind);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment