JavaScript

JavaScript

Made by DeepSource

Require $on and $watch deregistration callbacks to be saved in a variable JS-0529

Anti-pattern
Minor
angularjs

Watch and On methods on the scope object should be assigned to a variable, in order to be deleted in a $destroy event handler Rule based on Angular 1.x

Bad Practice

$rootScope.$on('event', function () {
    // ...
});

Recommended

$scope.$on('event', function () {
    // ...
});

var unregister = $rootScope.$on('event', function () {
    // ...
});