Watch value change
Description
The following code shows how to use $watch
to
watch value change.
Example
<!DOCTYPE html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {<!-- w w w. jav a2s .c om-->
$scope.value= 'foo';
$scope.$watch('value', function(value) {
console.log(value);
});
}
</script>
</head>
<body ng-app="myApp">
<div ng-controller="MyCtrl">
<input type="radio" ng-model="value" value="foo">
<input type="radio" ng-model="value" value="bar">
<input type="radio" ng-model="value" value="baz">
<hr>
{{value}}
</div>
</body>
</html>