Using reactive forms in Angular, what would be the inverse of patchValue?
this.form.patchValue(this.unobjeto);
I mean, how do I get all the fields of the form and assign them to an object, and then send it to the API to store it in the DB, thanks.
You can do
this.form.value
and you will get all the values that are not disabled.You can use
this.form.get('name')
to get the value of each of your form fields, where 'name' is the form control name.Example:
this.form.get('phone')
to get the phone number entered in the form.I share the documentation section where they explain it: https://angular.io/guide/reactive-forms#creating-dynamic-forms
Another option is to create a function that controls the Form .
Something like that:
Later, when you want to modify something in the form, you just call the function, for example something like this:
And if it is a text you put the '', something like this:
In case you have a variable:
It would look like this:
But the most direct way I think, maybe I'm wrong, is:
As previously commented.