Home > Article > Web Front-end > AngularJS's $watch method (monitoring actions)
1. Problem background
The $watch method in AngularJS to monitor data changes
2. Implementation source code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>AngularJS之$watch方法(监控动作)</title> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> <style> body{ font-size: 12px; font-family: "微软雅黑"; background-color: #F8EFC0; backface-visibility: visible; } p{ margin: 10px 10px 10px 10px; } </style> <script> var app = angular.module("watchApp",[]); app.controller("watchCon",['$scope',function($scope){ $scope.count = 0; $scope.username = ""; $scope.$watch('username',function(){ $scope.count++; }); }]); </script> </head> <body ng-app="watchApp"> <p ng-controller="watchCon"> <p> <input type="text" id="username" ng-model="username" maxlength="12" autocomplete="on"/> </p> <p> {{count}} </p> </p> </body> </html>
3. Implementation result
(1) Initialization
## (2) Change the input box value
## The above is the content of the $watch method (monitoring action) of AngularJS. For more related content, please pay attention to the PHP Chinese website (www .php.cn)!