Last active
August 29, 2015 13:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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