Sibi Raj Sibi Raj - 29 days ago 22
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

$scope.params={
privacy:true,
status: false
}


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

Answer

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);
Comments