title: Using $setValidity inside a Controller
body: <p>I am trying to do some validation on file change. Here is my code:</p>
  
  <p><strong>View/Template</strong></p>
  
  <pre><code>&lt;input type="file" name="file" id="file"  
         onchange="angular.element(this).scope().setFile(this)" 
         required /&gt;
  
  &lt;span class="error" ng-show="myForm.file.$error.required"&gt;Error&lt;/span&gt;
  &lt;span class="error" ng-show="myForm.file.$error.size"&gt;Selected file is too large&lt;/span&gt;
  &lt;span class="error" ng-show="myForm.file.$error.filetype"&gt;Unsupported File type&lt;/span&gt;
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>angular.module("myapp").controller("myctrl", function($scope) {
    $scope.setFile = function(element) {
      $scope.$apply(function($scope) {
        var fileObject = element.files[0];
        $scope.file.fileType = 
           fileObject.type.toUpperCase().substring(fileObject.type.indexOf("/") + 1);
  
        // Validation
        if (!$scope.isValidFileType($scope.file.fileType)) {
          myForm.file.$setValidity("myForm.file.$error.filetype", false);
        }
  
        if (fileObject.size &gt; 1000*1000*10) {
          myForm.file.$setValidity("myForm.file.$error.size", false);
        }
      });
    };
  
    $scope.isValidFileType = function(fileExtension) {
      var supportedExtensions = ["doc", "docx", "ppt", "pptx", "jpg", "gif", "png"]; // etc.
      return (jQuery.inArray(fileExtension, supportedExtensions) &gt; -1);
    }
  });
  </code></pre>
  
  <p>But right now the call to <code>$setValidity</code> is not working.<br>
  Any thoughts?</p>