简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM