title: Angular reactive forms, adding and removing fields?
body: <p>while building crud app in angular 5 I've come across with a question, how can I use the same form builder but change what form controls I get depending on what I want, adding or updating users thru form...</p>
  
  <p>Here's some simple code, I will try not to complicate things, since I have pretty big form with lot of attributes...</p>
  
  <p>So in my app.component.html i have form</p>
  
  <pre><code>         &lt;form class="form-horizontal" [formGroup]="form" #myForm="ngForm" 
            (ngSubmit)="save()"&gt; 
                  &lt;div class="form-group"&gt;
                      &lt;label for="firstName" class="control-label 
                    required"&gt;First name&lt;/label&gt;
                      &lt;input type="text" id="firstName" class="form-control" 
               formControlName="firstName"&gt;
  
  
                  &lt;/div&gt;
  
                  &lt;div class="form-group"&gt;
                      &lt;label for="lastName" class="control-label 
              required"&gt;Last name&lt;/label&gt;
                      &lt;input type="text" id="lastName" class="form-control" 
              formControlName="lastName"&gt; 
                  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>and in my app.component.ts</p>
  
  <p>in my constructor i have</p>
  
  <pre><code>    this.form = this.formBuilder.group({ 
          firstName: ['', [Validators.required, Validators.minLength(2), 
     Validators.pattern(/^[a-zA-Z]+$/)]],
          lastName: ['', [Validators.required, Validators.minLength(2), 
     Validators.pattern(/^[a-zA-Z]+$/)]],
  
      });
  </code></pre>
  
  <p>and save() function for submiting the form</p>
  
  <pre><code>    save() {
      let formModel = this.form.value;
      formModel.id = this.Id;
  
      if (this.Id == null) { 
          this._usermanagementservice.addEmployee(formModel).subscribe(() =&gt; {
  
             //function that reloads table with employees
              this.LoadAllEmployees();
          });
      }
      else {
          this._usermanagementservice.updateEmployee(this.Id, formModel).subscribe(() =&gt; {
              this.LoadAllEmployees();
          });
      }
  }
  </code></pre>
  
  <p>Noted that everything works, I've not included other fields, but here's the question, how can I include only form for first name field on adding user, and have ONLY last name for updating? (to simplfy things, I'm using this example first and last name)</p>
  
  <p>Thanks, If you need more info, I'll gladly provide it
  Ps. english is my secondary language, so terms like fields, forms and etc. are for sure incorrect, hopefully you'll get the point</p>