>  기사  >  웹 프론트엔드  >  AngularJS의 $watch 메서드(작업 모니터링)

AngularJS의 $watch 메서드(작업 모니터링)

黄舟
黄舟원래의
2017-02-18 13:36:161158검색

1. 문제 배경

데이터 변경을 모니터링하는 AngularJS의 $watch 메서드


2. 구현 소스코드

<!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",[&#39;$scope&#39;,function($scope){
				$scope.count = 0;
				$scope.username = "";
				$scope.$watch(&#39;username&#39;,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. 구현 결과

(1) 초기화

 AngularJS의 $watch 메서드(작업 모니터링)

(2) 입력란 값 변경

 AngularJS의 $watch 메서드(작업 모니터링)

위 내용은 AngularJS의 $watch 메소드(모니터링 액션) 내용입니다. PHP 중국어 웹사이트(www.php.cn)를 주목하세요!


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.