Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Created December 9, 2013 05:58
Show Gist options
  • Select an option

  • Save PatrickJS/7867918 to your computer and use it in GitHub Desktop.

Select an option

Save PatrickJS/7867918 to your computer and use it in GitHub Desktop.
var app = angular.module('YOUR_APP')
app.config(['$provide', function($provide) {
$provide.decorator('$rootScope', ['$delegate', function($delegate) {
Object.defineProperty($delegate.constructor.prototype, '$onRootScope', {
value: function(name, listener){
var unsubscribe = $delegate.$on(name, listener);
this.$on('$destroy', unsubscribe);
},
enumerable: false
});
return $delegate;
}]);
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment