Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

angular - Add multiple child form

I have a form like this . enter image description here

I want to add button (+) before Action N° : , each time I click on (+) it shows me a child-form if I have a second action to add. this child-form must contain only this fields.it's like I want this button to allow me to add several actions for this form, but the other fields must have a fixed value. enter image description here When I create this form I need to have data like this in my database . enter image description here

I m using spring boot in back end and postgres as database.

Any suggestion how we can do this ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
    matrimonyForm: FormGroup;
    
    constructor(public formBuilder: FormBuilder){
       this.matrimonyForm = this.formBuilder.group({contact_person: new FormArray([])});
    }    
    get c() { return this.matrimonyForm.controls['contact_person'] as FormArray; }
            
    Click on Add button call addMore()
    
    addMore(){
          this.c.push(this.formBuilder.group({ name: ['', Validators.required], contact_no: ['', Validators.required], relation: ['', Validators.required] }));
        }

now you can get dynamic *contact_person*

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...