-
Notifications
You must be signed in to change notification settings - Fork 0
/
exemplo 4.4 – watch.html
33 lines (29 loc) · 879 Bytes
/
exemplo 4.4 – watch.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!doctype html>
<html ng-app="myApp">
<body>
<div ng-controller="MyController">
<input type="text" ng-model="total" />
<button ng-click="increment()">Incrementar Total pelo Controller</button><br />
<hr />
<span>{{total}}</span>
<hr />
<b>$watch listener =</b> {{listenerMessage}}
</div>
<script src="angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('MyController', [ '$scope', function($scope) {
$scope.total = 0;
$scope.listenerMessage = '';
function totalChanged(newValue, oldValue) {
$scope.listenerMessage = 'Valor Antigo: ' + oldValue + ', Novo valor: ' + newValue;
}
// observa alterações de $scope.total
$scope.$watch('total', totalChanged);
$scope.increment = function(){
$scope.total++;
}
}]);
</script>
</body>
</html>