Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
AngularJS

$watch in AngularJS

Observe model changes with $scope.$watch and clean up on $destroy.

$watch in AngularJS — a practical guide to AngularJS $watch with clear examples you can reuse in real projects.

AngularJS Tutorial Series (88/99). Prefer one article? Read the complete AngularJS tutorial.

Short description

Deep watches (objectEquality true) are expensive — use carefully.

$watch

var off = $scope.$watch('vm.query', function (nv, ov) {
  if (nv !== ov) { vm.search(nv); }
});
$scope.$on('$destroy', off);

Leave a reply

Your email address will not be published. Required fields are marked *