A
A
Andrey Kharitonov2019-09-25 09:47:36
Angular
Andrey Kharitonov, 2019-09-25 09:47:36

How to pass form title in .html to .ts?

I want to pass on click to a function

addFields(addField: string, <тут название или массив формы из HTML>) {
    (<FormArray><тут название или массив формы из HTML>.controls[addField]).push(new FormGroup({
      date_from: new FormControl(''),
      date_to: new FormControl('')
    }));

the name of the current form. so as not to write separately this.myForm1, this.myForm2,... for each form.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2019-09-25
@AskiLD

addFields(addField: string, form: FormArray|FormGroup) {
    form.controls[addField]).push(new FormGroup({
      date_from: new FormControl(''),
      date_to: new FormControl('')
    }));

<button (click)="addFields('myField', myForm1)"></button>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question