title: Validation of dynamic angular2 forms
body: <p>I have a FormGroup with a template-driven validation. I need my form to have a section of dynamically generated inputs, created by ngFor. Unfortunately, angular2 now requires every input within FormGroup using ngModel to be named. How can I deal with it? Template-driven solution is preferred. </p>
  
  <p>Form code is as follows:</p>
  
  <pre><code>&lt;form #f="ngForm" (ngSubmit)="createProfile()"&gt;
      &lt;div class="row align-items-center mb-2"&gt;
          &lt;div class="col-sm-2"&gt;
              &lt;b&gt;Name:&lt;/b&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-10"&gt;
              &lt;input type="text" [(ngModel)]="profile.name" class="form-control"
              name="profileName" required pattern="[a-zA-Z_][a-zA-Z_\-0-9]*"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="channelBox"&gt;
          &lt;div *ngFor="let c of profile.channels"&gt;
              &lt;div class="row align-items-center mb-2"&gt;
                  &lt;div class="col-sm-2"&gt;
                      &lt;b&gt;Name:&lt;/b&gt;
                  &lt;/div&gt;
                  &lt;div class="col-sm-10"&gt;
                      &lt;input type="text" [(ngModel)]="c.name" class="form-control" required
                      pattern="[a-zA-Z_][a-zA-Z_\-0-9]*" name="channelName"&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="row align-items-center mb-2"&gt;
                  &lt;div class="col-sm-2"&gt;
                      &lt;b&gt;Filter:&lt;/b&gt;
                  &lt;/div&gt;
                  &lt;div class="col-sm-10"&gt;
                      &lt;textarea class="form-control" rows="4" [(ngModel)]="c.filter"
                      name="channelFilter"&gt;
                      &lt;/textarea&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="row align-items-center mb-2"&gt;
                  &lt;div class="col-sm-2"&gt;
                      &lt;b&gt;Sources:&lt;/b&gt;
                  &lt;/div&gt;
                  &lt;div class="col-sm-10"&gt;
                      &lt;label *ngFor="let s of c.sources"&gt;
                          &lt;input type="checkbox" [(ngModel)]="s.checked" 
                          name="channelCheck"&gt;
                          {{ s.name }}
                      &lt;/label&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div&gt;
          &lt;button class="btn btn-success" type="submit" [disabled]="!f.valid"&gt;
              Create profile
          &lt;/button&gt;
          &lt;button class="btn btn-default" (click)="d('reason')"&gt;Cancel&lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Thanks in advance for help</p>