How to 'unwatch' an expression

前端 未结 5 525
情深已故
情深已故 2020-11-30 19:21

Say I have an ng-repeat with a big array.

When ng-repeat runs, it adds every element of that array to an isolated scope, as well as having the array itself in a scop

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 19:31

    $watch returns a function that unbinds the $watch when called. So this is all you need for "watchOnce":

    var unwatchValue = scope.$watch('value', function(newValue, oldValue) {
      // Do your thing
      unwatchValue();
    });
    

提交回复
热议问题