title: Angular Forms reactive - cross-control validation
body: <p>I'm working on a validator for a reactive form in angular 5, and having difficulty setting a validator that is based on the value of another input.</p>
  
  <p>The form looks something like this:</p>
  
  <pre><code>let myRules = new FormArray([]);
  myRules.push(this.newRuleFormGroup(1, 'period', 1));
  
  this.myForm = new FormGroup({
        'name': new FormControl(name, [Validators.required, this.validate_usedName.bind(this)]), // V: must not exist already
        'icon': new FormControl(icon, [Validators.required]), // has default
        'rules': myRules
      })
  </code></pre>
  
  <p>'rules' is a <code>FormArray</code>, and I push new <code>FormGroup</code>s from the template using:</p>
  
  <pre><code>newRuleFormGroup = (amount: number, period: string, repAmount: number = 1) =&gt; {
      return new FormGroup({
        'amount': new FormControl(amount, [Validators.required]),
        'type': new FormControl(period, [Validators.required]),
        'repAmount': new FormControl(repAmount, [this.validate_repAmount.bind(this)])
      })
    }
  </code></pre>
  
  <p><code>repAmount</code> is only required when <code>type == "period"</code>. In the validator for <code>repAmount</code>, I am trying to reach the parent <code>FormGroup</code> and try to get the value of his child <code>'type'</code> control. Something like this:</p>
  
  <pre><code>validate_repAmount(control:FormControl): {[s:string]: boolean}{
    let type = control.parent.get('type');// Cannot read property 'get' of undefined
    let controlValue = control.value;
    console.log(control.parent); // returns the parent FormGroup object
    if(type.value == 'period' &amp;&amp; (controlValue != '' || controlValue&gt;0)) {
        return {'repAmountMissing':true};
    }
      return null;
    }
  </code></pre>
  
  <p>But I keep getting an error saying <code>Cannot read property 'get' of undefined</code>. If I try to <code>console.log(control.parent)</code>, i get the FormGroup object as expected, but I can't seem to access it in any way using its properties.</p>
  
  <p>Could anyone suggest a way to access the 'type' value in  the same group for the validator?</p>