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

142
Visualizações
Creating dynamic inputs in NgForm with child components

Hello Stack Overflow Community I hope you are having a great day, today I have an issue that I have been trying to figure out and I hope you can tell me how it is done.

Story
I'm trying to create a form with dynamic fields, meaning the form doesn't have defined FormControls, Validators, or anything.
It only has the fields that are active on the form when the form is submitted.\

Ex.
<child-component *ngIf="condition" ngModel ngDefaultControl></child-component>
Is now active and is in the NgForm object and can be sent to the database.
or
Is now not active and is not in the NgForm object and can then not be sent to the database.

The rest of the active fields are then in the object but not the deactivated <child-component>.
I have gotten this to work, however, I'm trying to add " error handling" to the <child-component> to check if the field is empty if it is required and if it is of the type that it is supposed to be Ex. number, text, etc.
I have issues with getting the " error handling" to work.

Question
How do I add an error to my <child-component> if it is required and empty or if the value of the <child-component> input is not of the same type as the input?

Link to StackBlitz (doesn't open in a new window)

Thank you for taking the time to help me out.

Best regards,
Alexander

about 4 years ago · Juan Pablo Isaza
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