<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>AngularJS Using scope.$watch</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.js"></script>
  <script>
    var app = angular.module("mywatch", []);
    var myController = app.controller("watchController", function($scope) {
      $scope.name = 'Anil Singh';
      $scope.counter = 0;
      $scope.$watch('name', function(newValue, oldValue) {
        $scope.counter = $scope.counter + $scope.name.length;
      });
    });
  </script>
</head>

<body ng-app="mywatch" ng-controller="watchController">
  <input type="text" ng-model="name" />
  <label>Counter: {{counter}}</label>
</body>

</html>
// Code goes here

/* Styles go here */