title: AngularJS - Prevent submission of a form if it is invalid
body: <p>I have created an isolated case of my issue:
  <a href="http://plnkr.co/edit/6LXW5TG76LC9LNSrdpQC" rel="nofollow noreferrer">http://plnkr.co/edit/6LXW5TG76LC9LNSrdpQC</a></p>
  <p>Here is the code of the isolated case:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html ng-app=&quot;App&quot;&gt;
  
      &lt;head&gt;&lt;/head&gt;
  
      &lt;body ng-controller=&quot;ExampleController&quot;&gt;
      
      &lt;form name=&quot;form&quot; ng-submit=&quot;submit()&quot; novalidate&gt;
          &lt;input type=&quot;number&quot; name=&quot;number&quot; ng-model=&quot;number&quot; required&gt;&lt;br&gt;
          &lt;span ng-show=&quot;form.number.$error.required &amp;&amp; form.number.$touched&quot;&gt;Required&lt;br&gt;&lt;/span&gt;
          &lt;span ng-show=&quot;form.number.$error.number&quot;&gt;Not a number&lt;br&gt;&lt;/span&gt;
          &lt;input type=&quot;submit&quot;&gt;
      &lt;/form&gt;
  
      &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js&quot;&gt;&lt;/script&gt;
      
      &lt;script&gt;
          
          var App = angular.module('App', []);
          
          App.controller('ExampleController', function($scope) {
          
          $scope.submit = function() {
              alert('send to server: ' + $scope.number);
          }
          
          });
          
          App.run();
          
      &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Basically, the example contains a number field, and beneath it are error messages that show when the input is invalid (empty or not a number).</p>
  <p>But the form will still submit, and although the field value is set to 'undefined' if it is not valid, I would prefer a way of checking if the form is valid before sending to the server (the alert box in this example).</p>
  <p>So my question is - In AngularJS, is there a way of checking if a form is valid from within a controller? Or another way to prevent a form from submitting if it is invalid?</p>