-
-
Save fercreek/3d46ff2bccd1ca42fc5c4af23dd0ed35 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