title: Directive that checks validation in AgualrJS - $scope is not defined error
body: <p>When I trying to do server-side validation on my &quot;name&quot;-field, by adding a directive:</p>
  <pre><code> app.directive('uniqueName', function($http) {
      var toId;
      return {
          require: 'ngModel',
          link: function(scope, elem, attr, ctrl) {
   
              scope.$watch(attr.ngModel, function(value) {
  
                      $http.get('/rest/isUerExist/' + value).success(function(data) {
  
                          //set the validity of the field
                          $scope.$apply(function(s) {
                              ctrl.$setValidity('uniqueName', data);
                          });
                      });
              })
          }
      }
  });
  </code></pre>
  <p>Why it returns <strong>&quot;$scope is not defined&quot;</strong> message in console??</p>
  <p><strong>UPDATE:</strong></p>
  <p>If I use&quot;scope.&quot; but not &quot;$scope.&quot;, then I have different error in the console:</p>
  <blockquote>
  <p>Error: $digest already in progress</p>
  </blockquote>