AngularJS: How to remove a watch

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

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.

Arne Hartherz