Level Up Your VS Code Snippets
November 21, 2022Creating A Basic Customisable PDF Viewer Using PDF.js
December 12, 2022When you have to render multiple forms within a parent form dynamically, then form arrays will be the best solution.
Let's Start
Start by importing the FormBuilder, FormArray and FormGroup packages into our project. FormBuilder will be used to construct a form array, including formControls, dynamically.
- We'll also create variables for each of these like so:
- Next we have to create an instance of a form array and assign it to our form array variable.
- I'll also create a form that will contain my form array as one of the form controls.
(note that the arrayOfForms form control is my array of forms).
- Then I also have to create another formGroup that will be pushed onto my form array. I can add as many forms in this form array as I want.
(note that row represents a single form in the form array variable formArray)
- Finally now you'll be able to add a form inside of your parent form at any time programatically. This form array acts just like a normal array, so you could also remove forms from this form array as you choose.