Last Updated: February 25, 2016
·
1.639K
· not-only-code

AngularJS Destroy $scope listeners

In AngularJS each listener on any $scope must be destroyed manually. To do that, when you creates a listener it returns a function to destroy it.

destroyCallback = $rootScope.$on 'my:event', ->
    console.log 'my code'

So you can destroy it when current $scope destroys

$scope.$on '$destroy', ->
    # unbind listener 'my:event'
    destroyCallback()