title: How can I attach a listener to a variable inside my angularjs controller?
body: <p>I want to attach a listener to my  titleChanged variable. 
  I've tried this way but it throws this error</p>
  
  <p>TypeError: this.$watch is not a function</p>
  
  <pre><code>        var titleChanged = false;
  
          function titleTrue() {
              titleChanged = true;
          };
          $scope.$watch('title',function(newValue, oldValue) {
              if (newValue !== oldValue) {
                  $timeout(titleTrue(), 5000)
              };
          });
          this.$watch('titleChanged', function(newValue){
              if(newValue === true) {
                      updateNote();
                      titleChanged = false;
                  };
          });
  </code></pre>
  
  <p>the updated code another apprach</p>
  
  <pre><code>        var titleChanged = false;
  
          $scope.$watch('title',function(newValue, oldValue) {
              if (newValue !== oldValue) {
                  titleChanged = true;
              }
          });
  
          while (true) {
              $timeout(checkForChangeAndSave, 3000);
          };
  
          function checkForChangeAndSave() {
              if(titleChanged) {
                  updateNote();
                  titleChanged = false;
              }
          }
  
  
          function updateNote() {
              notesService.update($stateParams.id, {title: $scope.title});
              notesService.getAll();
          };
  </code></pre>