Skip to content

Instantly share code, notes, and snippets.

@toddsby
Created May 31, 2014 15:31
Show Gist options
  • Select an option

  • Save toddsby/00d05dbd1c509ac1efcc to your computer and use it in GitHub Desktop.

Select an option

Save toddsby/00d05dbd1c509ac1efcc to your computer and use it in GitHub Desktop.
angularjs unsub from events on $scope change
angular
.module('MyApp')
.config(['$provide', function($provide){
$provide.decorator('$rootScope', ['$delegate', function($delegate){
$delegate.constructor.prototype.$onRootScope = function(name, listener){
var unsubscribe = $delegate.$on(name, listener);
this.$on('$destroy', unsubscribe);
};
return $delegate;
}]);
}]);
@toddsby
Copy link
Author

toddsby commented May 31, 2014

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