title: Trigger validation of a field when another field is changed
body: <p>I have a custom validation directive that is being called properly when one field is changed. However, whether this field is valid is also based on another field's value. This second field is a select list if that is of importance. </p>
  
  <p>I was wondering if there was some way I could trigger validation manually when the second form is changed. Perhaps by using the <code>ng-change</code> event. What is the proper way to handle something like this?</p>
  
  <p>Here is my directive:</p>
  
  <pre><code>angular.module('myApp', []).
      directive('validage', function () {
          return {
              require: 'ngModel',
              link: function (scope, elem, attr, ngModel) {
  
                  function validate(value) {
                      var valid = true;
                      if ((GetDateDifference(new Date(value), new Date()) &lt; 16 || GetDateDifference(new Date(value), new Date()) &gt; 129)
                      &amp;&amp; scope.dep.DependantType == "Spouse") {
                          valid = false;
                      }
                      ngModel.$setValidity('validage', valid);
                      return value;
                  }
  
                  //For DOM -&gt; model validation
                  ngModel.$parsers.unshift(function (value) {
                      var valid = true;
                      if ((GetDateDifference(new Date(value), new Date()) &lt; 16 || GetDateDifference(new Date(value), new Date()) &gt; 129)
                      &amp;&amp; scope.dep.DependantType == "Spouse") {
                          valid = false;
                      }
                      ngModel.$setValidity('validage', valid);
                      return value;
                  });
  
                  //For model -&gt; DOM validation
                  ngModel.$formatters.unshift(function (value) {
                      var valid = true;
                      if ((GetDateDifference(new Date(value), new Date()) &lt; 16 || GetDateDifference(new Date(value), new Date()) &gt; 129)
                      &amp;&amp; scope.dep.DependantType == "Spouse") {
                          valid = false;
                      }
                      ngModel.$setValidity('validage', valid);
                      return value;
                  });
              }
          };
      });
  </code></pre>
  
  <p>If you're new to AngularJS, I would definitely recommend reading these 2 articles: <a href="https://thebhwgroup.com/blog/2014/08/designing-html-forms-angularjs-part-1" rel="noreferrer">part 1</a> &amp; <a href="https://thebhwgroup.com/blog/2014/08/angularjs-html-form-design-part-2" rel="noreferrer">part 2</a>. They are an overview of AngularJS forms.</p>