0

If I were to create a $watch expression like:

         $scope.$watch(function(){
              return(MyDataStore.someInstanceVariable);}
          , function(newVal, oldVal){
               $scope.scopeVariable = newVal;}
          , true)

How often would this function execute? How often would it poll the data store? Just how (in)efficient is this approach?

Abraham P
  • 15,029
  • 13
  • 58
  • 126
  • 1
    It would poll the data store at least as many times as there are $digest loops. Read [Databinding in angularjs](http://stackoverflow.com/questions/9682092/databinding-in-angularjs) – Stewie Jun 19 '13 at 05:30

1 Answers1

1

From the angularjs docs:

The watchExpression is called on every call to $digest() and should return the value which will be watched. (Since $digest() reruns when it detects changes the watchExpression can execute multiple times per $digest() and should be idempotent.)

See the docs at: Angularjs Watch

Nir
  • 473
  • 1
  • 5
  • 10