formations/javascript/angular/scope-4.md

30 lines
590 B
Markdown
Raw Normal View History

# .cadoles-slide-title[L'objet $scope (4/4)]
**Observer les modifications du $scope**
```html
<html>
<body ng-app="myApp">
<div ng-controller="MainCtrl">
<input ng-model="message" />
</div>
<script src="angular.js"></script>
<script>
var myApp = angular.module('myApp', []);
myApp.controller('MainCtrl', ['$scope', function($scope) {
$scope.message = '';
$scope.$watch('message', function(newVal, oldVal) {
console.log('"message" a changé !', newVal, oldVal);
});
}]);
</script>
</body>
</html>
```