Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!