title: Angular 2 ng-required
body: <p>I made a model-driven form in angular 2, and one of the input fields must show up only if a checkbox above is unchecked.I did this with *ngIf.
  My question is how can I set that input required only if the checkbox is unchecked? In angular 1.x i could make this happen with the ng-required="condition" in the view.</p>
  
  <p>Here is the html:</p>
  
  <p>//the checkbox</p>
  
  <pre><code>&lt;div class="checkbox col-sm-9"&gt;
     &lt;label&gt;
       &lt;input type="checkbox"  id="getCompanyAddress" style="cursor: pointer;" [formControl]="form.controls['address']" &gt;Use the company address 
    &lt;/label&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>// the option input:</p>
  
  <pre><code>&lt;div *ngIf="form.value.address == false" class="form-group" [ngClass] = "{'has-error':!form.controls['address'].valid &amp;&amp; form.controls['address'].touched}" &gt;
   &lt;label for="add_gestion_adress" class="col-sm-3 control-label"&gt;Address
   &lt;/label&gt;
    &lt;div class="col-sm-9"&gt;&lt;textarea rows="1" id="add_gestion_adress" class="form-control" name="add_gestion_adress" [formControl]="form.controls['address']" &gt;&lt;/textarea&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>//and the model code:</p>
  
  <pre><code>   form: FormGroup;
      constructor(fb:FormBuilder){
        this.form = fb.group({
          'name': [null,Validators.compose([Validators.required, Validators.minLength(1)])],
          'type': ["en gros",Validators.compose([Validators.required, Validators.minLength(2)])],
          'person':[null,Validators.compose([Validators.required, Validators.minLength(1)])],
          'address':[false,Validators.compose([Validators.minLength(1)])],
          'locality':[null, Validators.compose([Validators.required])],
          'county':[null,Validators.compose([Validators.required])],
          'country':[null,Validators.compose([Validators.required])]
        })
  
      }
  </code></pre>