Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
How to patch a reactive form with multi nested json values

I am using the value of a multi nested (Infinity level) reactive form which contains formArray, formGroups and formControls. Which is stored in DB.

Currently, I am patching the form using a recursion function that loops through the entire JSON and makes formArrays, formGroups and formControls based on keys and values.

Now the issue is, this method which I am using is not good as per performance perspective, so is there any better way to patch this kind of multi nested form in one go? (Just create form, no need to show in HTML)

This is simplified JSON for question reference -

Any section can have subSections and then subSections can have some kind of section

const formDataSections = [
  {
    index: 1,
    sectionName: "",
    subSections: [
      {
        index: 1,
        subSectionName: "",
        sections: [
          {
            index: null,
            sectionName: "",
            subSections: [
              {
                index: null,
                subSectionName: "",
                sections: [
                  {
                    index: null,
                    sectionName: "",
                  },
                  {
                    index: null,
                    sectionName: "",
                    subSections: [
                      {
                        index: null,
                        subSectionName: "",
                        sections: [
                          {
                            index: null,
                            sectionName: "",
                          },
                          {
                            index: null,
                            sectionName: "",
                            subSections: [],
                          },
                        ],
                      },
                    ],
                  },
                ],
              },
            ],
          },
          {
            index: null,
            sectionName: "",
            subSections: [
              {
                index: null,
                contentTypes: [],
                sections: [
                  {
                    index: null,
                    sectionName: "",
                    subSections: [],
                  },
                ],
              },
            ],
          },
        ],
      },
    ],
  },
];
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You could create a custom "subform" component using ControlValueAccessor (docs) and call the component recursively (example)

I don't think you can avoid recursion since the list has potentially infinite length

Here's a (not fully working...) StackBlitz example, just to showcase what I'm talking about.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda