Last Updated: February 25, 2016
·
361
· nilpath

AngularJS: Scope.$watch

Maybe not that much of a pro tip, more of a reminder to self that you can compare the old value to the new value in the $watch listener function to not run the code block when the listener was called due to initialization..

From documentation...
To detect this scenario within the listener fn, you can compare the newVal and oldVal. If these two values are identical (===) then the listener was called due to initialization.

http://docs.angularjs.org/api/ng.$rootScope.Scope#$watch