title: Angular Reactive Forms Generate Form Controls from Type
body: <p>So, I have my Client class in TypeScript, let's say I have:</p>
  
  <pre><code>export class Client {
     id: string = '';
     name: string = '';
     email: string = '';
  }
  </code></pre>
  
  <p>Now every time I want to create a new Client I need a form, that's how I build it:</p>
  
  <pre><code>this.currentClient = new FormGroup({
    id: new FormControl(null, Validators.required),
    name: new FormControl(null, Validators.required),
    email: new FormControl(false)
  }
  </code></pre>
  
  <p>Then I add the form to the html:</p>
  
  <pre><code>    &lt;form [formGroup]="currentClient" (submit)="submit($event)"&gt;
          &lt;div class="form-group"&gt;
              &lt;input type="text" formControlName="id" class="form-control" placeholder="Id"&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;input type="text" formControlName="name" class="form-control" placeholder="Name"&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;input type="text" formControlName="email" class="form-control" placeholder="Email"&gt;
          &lt;/div&gt;
  
          &lt;button  [disabled]="currentContragent.invalid" class="btn btn-primary" type="submit"&gt;Submit&lt;/button&gt;
  
      &lt;/form&gt;
  </code></pre>
  
  <p>That's fine but I have some really big classes with more than 30 fields inside. For each, I have to create a TS class, a form group and I have to add it to the html. Is there anything like:</p>
  
  <pre><code>this.currentClient = formGroupFromType(typeof(Client));
  </code></pre>
  
  <p>And then something that could automatically generate my html using ng-for or something?</p>
  
  <p>I was thinking of building my own class that could hold property name, type, default value, isRequired and some other information like what editor (textbox, numeric textbox, etc). Having a list of properties defined like this could be used to generate the form group and the html, but it won't be strongly typed as I don't see how it could be connected to the Client class.</p>
  
  <p>Any ideas or suggestions?</p>