Skip to content

Instantly share code, notes, and snippets.

@toddmotto
Last active September 14, 2016 04:59
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save toddmotto/eb1767e5f3f4ab4fcefa to your computer and use it in GitHub Desktop.
Save toddmotto/eb1767e5f3f4ab4fcefa to your computer and use it in GitHub Desktop.
Automatic unbinding on $scope.$destroy for $rootScope listeners
/*!
* $rootScope listeners, remember to unbind on $destroy
*/
var $rootListeners = {
'transmitProgress': $rootScope.$on('transmit:progress', transmitProgress),
'transmitSuccess': $rootScope.$on('transmit:success', transmitSuccess),
'transmitError': $rootScope.$on('transmit:error', transmitError)
};
// iterate the Object and pass the methods to be called on $destroy
for (var unbind in $rootListeners) {
$scope.$on('$destroy', $rootListeners[unbind]);
}
@Frankistan
Copy link

It seems to be a perfect solution but...where or which file do I have to put that code?

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