Closed michaelspeed closed 6 years ago
I think that you want to store the values of form in db, you can use the value property of control.
but then i cannot revive it from there, is there a way to store the value with the controls?
Why do you want to store the controls in your database, can you please specify your use case
if i need to edit the form or view the form ?
Create Mode : You just need to save the values in your db. Edit Mode: You can use the patchValue function to set the values of your form controls that's it.
Please refer the docs for better explanation
this.form.patchValue({
name: "Something",
gender: "Male"
})
patchValue does not work if there are arrays in the values.
You have to do something like this.
const items = [
{
name: "item1",
description: "desc 1"
},
{
name: "item2",
description: "desc 2"
}
];
items.forEach((item, index) => {
this.addItem();
this.productForm
.get("items")
.at(index)
.patchValue(item);
});
Check out https://codesandbox.io/s/nw9wxw2nvl
thank will try it
how can i store the form state in a db ?