1.

Why is $watch used?

Answer»

$WATCH is used for keeping track of the OLD and new values of the expression or the MODEL variable that is being watched. ONE such usage is as shown below:

$scope.$watch("trackedVariable", function (newValue, oldValue){ console.log("Value Changed : ", newValue); });

In the above example, we are WATCHING the model variable named trackedVariable. If its value changes, we are immediately printing on the console.



Discussion

No Comment Found