title: Best way to put FormGroup into a Class
body: <p>I'm new to Reactive Forms, I use to work with template driven forms.</p>
  
  <p>I'm following the tutorial here: <a href="https://angular-templates.io/tutorials/about/angular-forms-and-validations" rel="noreferrer">https://angular-templates.io/tutorials/about/angular-forms-and-validations</a></p>
  
  <p>I have a User Class:</p>
  
  <pre><code>export class User {
    public pseudo: string;
    public email: string;
    public password: string;
  
    public constructor(init?: User) {
      Object.assign(this, init);
    }
  }
  </code></pre>
  
  <p>And I got my FormGroups in a component:</p>
  
  <pre><code> this.matching_passwords_group = new FormGroup(
        {
          password: new FormControl(
            '',
            Validators.compose([
              Validators.minLength(5),
              Validators.required,
              Validators.pattern(
                '^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$'
              )
            ])
          ),
          confirm_password: new FormControl('')
        },
        (formGroup: FormGroup) =&gt; {
          return PasswordValidator.areEqual(formGroup);
        }
      );
  
      // user details form validations
      this.userDetailsForm = this.fb.group({
        pseudo: new FormControl('', Validators.required),
        email: new FormControl(
          '',
          Validators.compose([
            Validators.required,
            Validators.pattern('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$')
          ])
        ),
        matching_passwords: this.matching_passwords_group,
        terms: new FormControl(false, Validators.pattern('true'))
      });
    }
  </code></pre>
  
  <p>As you can see there's a nested <code>formGroup</code> for password confirmation (to check that both password are equals).</p>
  
  <p>Then when user clicks on submit I want to transform my <code>formGroup</code> values into my User object.</p>
  
  <p>I followed what's recommended here: <a href="https://stackoverflow.com/questions/49997765/reactive-forms-correctly-convert-form-value-to-model-object">Reactive Forms correctly convert Form Value to Model Object</a></p>
  
  <p>Here my submit method:</p>
  
  <pre><code>onSubmitUserDetails(value) {
      this.newUser = new User(this.userDetailsForm.value);
  }
  </code></pre>
  
  <p>But obviously, with the nested password <code>formGroup</code> I don't have what I need in <code>this.newUser</code>: </p>
  
  <blockquote>
    <p>{email: "test@test" matching_passwords: {password: "Test1",
    confirm_password: "Test1"} pseudo: "test" terms: true}</p>
  </blockquote>
  
  <p>I could set values one by one but could be very long for bigger forms. Is there any handy way to set <code>formGroup</code> values into a class and solve problem with the nested password <code>formGroup</code>? How are we supposed to achieve that?</p>
  
  <p>Is the best solution to have my User object reflecting exactly the formGroups structure, and then exclude useless fields (like password confirmation) when I send my object to the API?</p>
  
  <p>Also what if I had a nested object in my User class, let say a collection of Books for instance, how am I supposed to transform nested FormGroups to match with the classes structure?</p>