Recently, I asked the following question on StackOverflow and received an amazing response that resulted in building a recursive nested Angular Form: Angular Deeply Nested Reactive Form: Cannot find control with path on nested FormArray . Here is a blog post written by the author about the same question
This recursive nested Angular Form lets me continue to build group FormArrays
, all of which have a group
object:
{
"conjunctor": null,
"conditions": [
{
"variable":
}
"groups": []
}
You can add multiple instances of conditions
and further nest the groups
as shown in this StackBlitz
Essentially, the Form component has been split up into multiple components:
group-control
, condition-form
, and action-buttons-bar
(the buttons to emit actions). This approach does everything I need, however, I am having troubles patching form values via this recursive approach.
So far I have tried sending in a static statement object and patching it both into the entire form itself, as well as specifically targeting the groups
object. Here is what this looks like in the
AppComponent:
(I have tried the same and similar approaches within the group-control
component as well). Eventually I plan on using data from an API to populate and patch these values, but for now and testing, using this static data
ngOnInit() {
const data = {
statement: {
groups: [
{
conjunctor: "and",
conditions: [
{
variable: "asdf"
}
],
groups: []
}
]
}
};
this._form.patchValue(data);
console.log(this._form.value);
}
Is it possible to patch the form value of the statement
FormGroup
on a recursive Form?