In the previous post, we created a simple service called deregister
to make event listeners deregistration easier. But sometimes you don’t even need to listen to an event more than once, and then the deregistration task is boring. No more!
If you have used AngularJS, you probably have at least once used the Scope.$on
or Scope.$watch
methods, and probably had to dispose of listeners / watchers. Here’s a little trick you may like to do just that in a few lines.