December 2014
Intermediate to advanced
346 pages
6h 14m
English
Nothing boosts watcher performance quite like destroying the watcher altogether. Should you encounter a scenario where you no longer have a need to watch a model component, invoking watch creation returns a deregistration function that will unbind that watcher when called.
When a watcher is initialized, it will return its deregistration function. You must store this deregistration function until it needs to be invoked. This can be done as follows:
$scope.myObj = {}
// watch myObj by reference
var deregister = $scope.$watch('myObj', function(newVal, oldVal, scope) {
// callback logic
});
// prevent additional modifications from invoking the callback
deregister();Read now
Unlock full access