iegorov
12/8/2014 - 5:35 AM

How do I ignore the initial load when watching model changes in AngularJS

How do I ignore the initial load when watching model changes in AngularJS

//set a flag just before the initial load,

var initializing = true
//and then when the first $watch fires, do

$scope.$watch('fieldcontainer', function() {
  if (initializing) {
    $timeout(function() { initializing = false; });
  } else {
    // do whatever you were going to do
  }
});
//The flag will be tear down just at the end of the current digest cycle, so next change won't be blocked.