1

I am using angular 5 and create a reactive form where implement a multiple add input field. This form has a index value that increment form loop ordering. I am using a model to get data. Every data i am getting and working fine but there was some problem, i cant get input field value that auto increment according to loop. here is my code sample.

<form [formGroup]="myForm" novalidate (ngSubmit)="createSurveys(myForm.value)">

<input type="number" class="form-control" [value]="i" formControlName="index" >

</form>


this.myForm = this._fb.group({
        name: ['', [Validators.required,Validators.minLength(5)]],
        question_record: this._fb.array([
            this.initQuestions()
        ])
    });

initQuestions() {
    return this._fb.group({
        index: [0]
    });
}

result

{
 "name": "abcde",
 "data": [
    {
      "title": "sssss",
      "index": 0
    },
    {
      "title": "ssss",
       "index": 0,
    }
  ]
}

when i console my data all data working find but i cant get index data and it always show default value that i set into the model that is 0.

1 Answer 1

2

Use formArray for looping this._fb.array([])

Example here https://stackblitz.com/edit/angular-aw5zpx?file=app%2Fapp.component.ts

Sign up to request clarification or add additional context in comments.

3 Comments

<input type="number" class="form-control text-center" id="index" formControlName="index" [value]="i"> problem is that want to get index value but always show default value
understand but u get data from click index button. my problem is how to get value from input such as want to get value <input type="text" formControlName=index value="0"> <input type="text" formControlName=index value="1"> <input type="text" formControlName=index value="2"> this value i want to set my model . please give me solution for this problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.