Read more

AngularJS: How to remove a watch

Arne Hartherz
December 12, 2014Software engineer at makandra GmbH

Sometimes you want Angular to watch an object only until a certain state is reached (e.g. an object appears in the scope).

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Angular's $watch returns a method that you can call to remove that watch. For example:

unwatch = $scope.$watch 'user', (user) ->
  if user?
    ... # do something
    unwatch()

That's it.

Posted by Arne Hartherz to makandra dev (2014-12-12 10:59)