inwxxg
Last Updated: February 25, 2016
·
840
· not-only-code
6ae4b2c6d61d56491b1fc24a66c28540

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()
Say Thanks
Respond