Sibi Raj Sibi Raj - 1 year ago 99
AngularJS Question

Watching any changes in ngmodel

I have defined ng-model ad

<input type="checkbox" name="check" ng-model="params.privacy">

I have my controller code as

status: false

How to watch any changes of the terms inside the $scope.params

Answer Source

You can do it like this:

$scope.$watch('params.privacy', function(new, old) {
   // triggered when `params.privacy` is changed

Or if you want to watch all properties, use deep watch:

$scope.$watch('params', function(new, old) {
   // triggered when any `params` property is changed
}, true);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download