Last Updated: February 25, 2016
·
5.768K
· yassershaikh

How to use $watch in AngularJs

$watch is an important feature present in AngularJs. It can be used to keep a watch on any value and trgiiger a function when that value changes.

In the below snippet, a watch is kept on the 'DollarRate' object present in the scope of the controller where this watch is defined.

$scope.$watch('DollarRate', function(newValue, oldValue) {
    // do something with the new or the old value.
});

Interview Questions And Answers

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
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