title: AngularJS 'controller as' and form.$valid
body: <p>I want to check if a form is valid inside an angular controller. This seems straightforward when using $scope, but I can't get it to work with the 'controller as' syntax. </p>
  
  <p>When I attempt to access form.$valid I get the error message <em>"Cannot read property '$valid' of undefined"</em>.</p>
  
  <p>plunkr: <a href="http://plnkr.co/edit/w54i1bZVD8UMhxB4L2JX?p=preview" rel="noreferrer">http://plnkr.co/edit/w54i1bZVD8UMhxB4L2JX?p=preview</a></p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;div ng-app="demoControllerAs" ng-controller="MainController as main"&gt;
    &lt;form name="contactForm" novalidate&gt;
      &lt;p&gt;
        &lt;label&gt;Email&lt;/label&gt;
        &lt;input type="email" name="email" ng-model="main.email" required /&gt;
      &lt;/p&gt;
      &lt;p&gt;
        &lt;label&gt;Message&lt;/label&gt;
        &lt;textarea name="message" ng-model="main.message" required&gt;&lt;/textarea&gt;
      &lt;/p&gt;
      &lt;input type="submit" value="submit" ng-click="main.submit()" /&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>var app = angular.module('demoControllerAs', []);
  
  app.controller('MainController', [function () {
      var main = this;
  
      main.submit = function () {
          var isValid = main.contactForm.$valid;
          console.log(isValid);
      };
  }]);
  </code></pre>