Last active
September 14, 2016 04:59
-
-
Save toddmotto/eb1767e5f3f4ab4fcefa to your computer and use it in GitHub Desktop.
Automatic unbinding on $scope.$destroy for $rootScope listeners
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
/*! | |
* $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]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems to be a perfect solution but...where or which file do I have to put that code?