Search code examples
angulartypescriptangular-reactive-formsangular-forms

Create whole dynamic form each time user clicks button add in Angular


No I have a form field using angular and I want to replicate whole form each time user clicks in a add button. Each new row form will be a separatly request to the server using RxJS

At the end will be a "run" button, enabled when all form info will be added.

How can I do it? Any example to follow?

Thank you very much


Solution

  • It's simple you just need to create array of FormGrop like

    forms: FormGroup[]
    

    and on add form button click you just need to add new form into that

    Here is the example code https://stackblitz.com/edit/angular-multiple-dynamic-form

    Example App: https://angular-multiple-dynamic-form.stackblitz.io