Model Driven / Reactive Forms: Auto mapping from Model to FormGroup ?

Viewed 2272

is there a way to automatically create a FormGroup from a Model? If i have a Model with multiple Properties:

Model: Person

firstName: string,
lastName: string,
street: string
country: string
....

and i want to create a simple FormGroup out of it:

Form: FormGroup

firstName: FormControl,
lastName: FormControl,
street: FormControl,
country: FormControl
....

It seems to 'dirty' to me, to explicitly define for each property in the Model a FormControl / FormGroup / FormArray:

formBuilder.group({
  firstName: person.firstName,
  lastName: person.lastName,
  street: person.street,
  country: person.country,
  ...
});

Each time the API from the Backend changes i have to adjust the model AND the form mapping. Is there some kind of generator which helps me to automate the mapping / creation of a FormGroup ?

1 Answers
Related