HLJ 发布于
2018-08-15 14:33:51

AngularJS $watch()函数

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>
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2018-08-15/98.html
最后生成于 2024-05-27 22:52:57
此内容有帮助 ?
0