title: Validation strategies with AngularJS
body: <p>I'm evaluating AngularJS and so far I'm very enthusiastic about it. But there's something missing on the validation front: the available options, such as the <a href="http://docs.angularjs.org/guide/forms" rel="noreferrer">built-in mechanisms</a> and the <a href="http://angular-ui.github.com/" rel="noreferrer">AngularUI initiative</a>, implement validators through directives and, as such, every validation should be declared in the view:</p>
  
  <pre><code>&lt;form ng-controller="SomeController"&gt;
      &lt;!-- Notice the 'required' attribute directive below: --&gt;
      &lt;input type="text" ng-model="user.name" name="uName" required /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>In this example, the view is defining that <code>user.name</code> is required. It's like saying the view defines the proper shape of the model. Isn't it a little backwards? Shouldn't the view reflect the states, including error states when it's the case?</p>
  
  <p>Am I mistaken? I'm wondering if it's possible to apply any validators in the <strong>controller</strong>, signaling the model's data as valid/invalid, and updating the view accordingly (painting form controls with red, showing error messages, clearing previous errors and so on). I'm assuming AngularJS is powerful enough for this, but in the docs and samples so far I just haven't seen anything like I've described above. Thanks!</p>