drenzzo
9/26/2019 - 4:18 PM

$destroy or clear $watch in angularjs

// call to $watch will return a de-register function
var listener = $scope.$watch(someVariableToWatch, function(....));

$scope.$on('$destroy', function() {
    listener(); // call the de-register function on scope destroy
});