title: Set values into a map<object, string> from form Angular 6
body: <p>I'm set keys and values into a map from a form and for every field I'm making a validation if this field is not null. I'm looking for a better solution... To make my code more clean because I have more than 10 fields...</p>
  
  <p>Here is my component.ts file:</p>
  
  <pre><code>const map = new Map&lt;Object, string&gt;();
  
      if (this.form.value.value1!= null) {
          map[KEY.VALUE_1] = this.form.value.value1;
      }
      if (this.form.value.value2!= null) {
          map[KEY.VALUE_2] = this.form.value.value2;
      }
      ...
  </code></pre>
  
  <p>Here is my component.html file:</p>
  
  <pre><code>&lt;div [formGroup]="form"&gt;
                  &lt;fieldset&gt;
                      &lt;legend&gt;Values&lt;/legend&gt;
                          &lt;mat-form-field &gt;
                              &lt;input matInput placeholder="value1" formControlName="value1"&gt;
                          &lt;/mat-form-field&gt;
  
                          &lt;mat-form-field&gt;
                              &lt;input matInput placeholder="value2" formControlName="value2"&gt;
                          &lt;/mat-form-field&gt;
                       ...
  
                  &lt;/fieldset&gt;
  &lt;/div&gt;
  </code></pre>