How do I stop $watching in AngularJS?

Solution 1:

When calling $watch a function is returned that unregisters the bound expression.

E.g., to watch a variable foo only change once:

var unregister = $scope.$watch('foo', function () {
  // Do something interesting here ...
  unregister();
});

Hope that helps :-)

Solution 2:

As an additional comment, but not answer - this is the same principle for killing event listeners as well.

var unregister = $rootScope.$on("listen-for-something-cool", function($event, params) {
   //Do cool stuff with params, then kill it
   unregister();
};

Just an addition I thought would be cool for anyone else to know...