AngularJS $watch()函数
html代码:
<body>
<div ng-app="watchApp" ng-controller="watchCtrl">
<h2>AngularJS $watch() Function Example</h2>
Enter Text:<input type="text" ng-model="txtval" /><br /><br />
<span style="color:Red">No. of Times $watch() Function Fired: {{count}}</span>
</div>
</body>
JavaScript代码:
<script type="text/javascript">
var app = angular.module('watchApp', []);
app.controller('watchCtrl', function ($scope) {
$scope.count = -1;
$scope.$watch('txtval', function (newval, oldval) {
$scope.count = $scope.count + 1;
});
});
</script>