Michael Michael - 1 year ago 121
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 () {

Answer Source

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

var listener = $scope.$watch("tag", function () {
    // ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download