title: AngularJS custom form validation error message
body: <p>Is there any way to pass an error message in custom form validation?</p>
  
  <p>E.g. I have a directive that checks a username. There are three possible outcomes:</p>
  
  <ol>
  <li>It is valid</li>
  <li>It is invalid because it isn't a good username ("this.is-invalid")</li>
  <li>It is invalid because it is already in use</li>
  </ol>
  
  <p>I have a directive like (simplified pseudo-html):</p>
  
  <pre><code>&lt;input type="text" namecheck&gt;&lt;/input&gt;&lt;span ng-show="name.$error.namecheck"&gt;You had an error {{ error }}&lt;/span&gt;
  </code></pre>
  
  <p>And in my custom directive, I can do</p>
  
  <pre><code>// check for a conflict and valid name here
  ngModel.$setValidity("namecheck",false);
  </code></pre>
  
  <p>But how do I pass an error message that indicates if the problem was a conflict or invalid name? Is there anything like <code>ngModel.$setValidityErrorMessage()</code> ?</p>