Michael Michael - 9 months ago 72
AngularJS Question

Unbinding $watch in angularjs after called

I know you can unbind a $watch like this:

var listener = $scope.$watch("tag", function () {});
// ...
listener(); // would clear the watch

but can you unbind the watch within the watch function declaration. So after the watch gets executed once, it unbinds itself? Something like:

$scope.$watch("tag", function () {


you can just do it the same way you already do, call the "deregistration" inside your function:

var listener = $scope.$watch("tag", function () {
    // ...