$watch vs. ngChange $watch vs. ngChange angularjs angularjs

$watch vs. ngChange


Bottom line - You can achieve with $watch every thing you can achieve with ng-change but not vice-versa.

Purposes:

ngChange - binded to a HTML element

$watch - observing scope's model objects (HTML object models included)

My rule of thumb - if you can use ng-change use it to match your scenario, otherwise use $watch

Why you shouldnt use $watch?

  1. It’s inefficient - Adding complexity to your $digest
  2. It’s hard to test effectively
  3. It's not clean


You have it mostly right. ng-change is very DOM specific and for evaluating an expression when the change event fires on a DOM element.

$watch however, is a lower-level (and more general purpose) utility that watches your view model or $scope. So your watch function will fire every time the user types a key (in the example of an input).

So to contrast, one listens to DOM events, the other watches your data.


$watch adds more complexity do the $digest, making it less efficient. In your case ngChange it's a cleaner and easier solution...

Font: http://www.benlesh.com/2013/10/title.html