title: Is it possible to pass dynamic values to a custom form validator in Angular 6?
body: <p>basically, i have some form inputs whose validations are dependent on each other (i.e. if you're putting in a time range, the "from" time must be smaller than the "to" time) but i'm not exactly sure how to go about this.</p>
  
  <p>Here is my form group:</p>
  
  <pre><code>this.form = this.fb.group({
    fromTime: ["", [Validators.required, CustomValidator.myValidationFunction(this.form.get("toTime").value)]],
    toTime: ["", [Validators.required]]
  });
  </code></pre>
  
  <p>And here is my validator so far:</p>
  
  <pre><code>static myValidationFunction(testing) {
      const toTime = testing; // only comes here 1 time
      return control =&gt; {
        return toTime /*this value never changes*/  ? null : { test: {} };
      };
    }
  </code></pre>
  
  <p>but it seems as though the value <code>x</code> or <code>toTime</code> is only set the first time when the validator is created. is there a way to pass dynamic inputs to a custom validator? </p>
  
  <p>I'm fairly new to angular, but have read the docs on <a href="https://angular.io/guide/form-validation#custom-validators" rel="noreferrer">custom form validation</a> but can't seem to find my answer</p>