Angular 2 conditional Validators.required?
<p>How should I go about conditionally requiring a form field? I made a custom validator, but the conditional variables that I pass to the custom validator are static and remain their initial values. What should my custom validator look like to get updated conditional values? Perhaps there is a way to do this with <code>Validators.required</code> instead of a custom validator?</p>

<pre><code>private foo: boolean = false;
private bar: boolean = true;

constructor(private _fb: FormBuilder) {
    function conditionalRequired(...conditions: boolean[]) {
      return (control: Control): { [s: string]: boolean } =&gt; {
        let required: boolean = true;
        for (var i = 0; i &lt; conditions.length; i++) {
          if (conditions[i] === false) {
            required = false;
          }
        }
        if (required &amp;&amp; !control.value) {
          return { required: true }
        }
      }
    }
    this.applyForm = _fb.group({
          'firstName': ['', Validators.compose([
            conditionalRequired(this.foo, !this.bar)
          ])],
          ...
    });
}
</code></pre>

<p><strong>Update (May 17, 2016)</strong></p>

<p>It's been a long time since posting this, but I'd like to reference the <code>.include()</code> and <code>.exclude()</code> methods available on the <code>ControlGroup</code> class for anyone out there who is trying to create this functionality. (<a href="https://angular.io/docs/ts/latest/api/common/index/ControlGroup-class.html" rel="noreferrer">docs</a>) While there are probably use cases for a conditional Validator like above, I've found the inclusion and exclusion of controls, control groups, and control arrays to be a great way to handle this. Just set the <code>required</code> validator on the control you'd like and include/exclude it as you please. Hope this helps someone!</p>