Using $watch to Track a Scope Variable

To add the capability to handle changes to scope values, you simply need to add a $watch to the variable in the scope using the $watch functionality built into AngularJS. The $watch function in the scope uses the following syntax:

$watch(watchExpression, listener, [objectEquality])

The watchExpression is the expression in the scope to watch. This expression is called on every $digest() and will return the value that will be watched. The listener defines a function that will be called when the value of the watchExpression changes to a new value. The listener will not be called if the watchExpression is changed to the value it is already set to. The objectEquality is a Boolean ...

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.