title: re-evaluate custom validator directive on input change
body: <p>I have a custom directive validator that uses an input to check validity. Using the original value, the validity works just fine. If I update the input, though, the validator still says the error and does not re-evaluate the value. How can I force a re-evaluation upon an update to the input?</p>
  <p>directive:</p>
  <pre><code>export class TimeRangeValidatorDirective implements Validator {
      @Input() maxTime;
      @Input() minTime;
  
      validate(control: AbstractControl): ValidationErrors | null {
          return CustomValidators.timeRange(this.maxTime, this.minTime)(control);
      }
  }
  </code></pre>
  <p>When min or max time update, I would like to cause the validation to re-run so that if the new max is above the control value or the new min is below it, previous errors will not persist</p>
  <p><strong>EDIT</strong>
  Based on the answer given by @Kevin Zhang (re-writing it here for clarity)</p>
  <p>The solution:</p>
  <pre><code>export class TimeRangeValidatorDirective implements Validator {
      private _onChange?: ()=&gt;void;
      private _maxTime;
      private _minTime;
  
      @Input() 
      get maxTime() { return this._maxTime}
      
      set maxTime(value) {
          this._maxTime = value;
          if(this._onChange) {
              this._onChange();
          }
      }
  
      @Input() 
      get minTime() { return this._minTime}
      
      set minTime(value) {
          this._minTime = value;
          if(this._onChange) {
              this._onChange();
          }
      }
  
      validate(control: AbstractControl): ValidationErrors | null {
          return CustomValidators.timeRange(this.maxTime, this.minTime)(control);
      }
  
      registerOnValidatorChanges(fn:()=&gt;void): void {
          this._onChange = fn;
      }
  }
  </code></pre>