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.
Written by Christoffer Åhrling
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Angularjs
Authors
Related Tags
#angularjs
Did you know?
AngularJS pages are long-lived browser apps with the same script risk as a newer single-page app. Third-party code in the template can read forms and values rendered on the page.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#