0

i'am creating nested form array that structured like this enter image description here

the form got an error when i want to add array into objects

enter image description here

here is the plnkr

if you have difficulty to understand,please tell me.

11
  • Share some code please. Commented Apr 25, 2017 at 3:35
  • @MrJSingh i already include the code..here once more plnkr.co/edit/foJsKKa08lgd5KuAghMU?p=preview Commented Apr 25, 2017 at 3:42
  • sorry i forgot the plnkr part. Commented Apr 25, 2017 at 3:49
  • You need to do nested loop inside the html Commented Apr 25, 2017 at 4:15
  • @Vignesh can you elaborate more..i dont understand Commented Apr 25, 2017 at 4:23

2 Answers 2

2

The only error you seem to have in your plunker, is the iteration of the surveys array, instead of:

*ngFor="let survey of myForm.controls.objects.controls; let j=index"

it should be:

*ngFor="let survey of object.controls.surveys.controls; let j=index"

where object refers to the iterations of objects form array in the higher level iteration.

So now when clicking Line End button in the Survey tab is working fine, see the forked Plunker

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

4 Comments

tq..you just save me.
do you know how to show latest arrayForm and hide the previous one? please help me
Do you mean to show only the latest object in a form array? Well, I guess you could set an if-statement to only show the last one based on the length of the array, but that would of course hide the others, what if user wants to revisit other form object in that array?
yes, i want to show only latest objecs as it was requested by user. i had try if-statement but didn't work.
0

See Your code the error states that the surveys object is not binded while looping.You need to loop properly in HTML .Check the below code

     <div *ngFor="let item of formvalue.objects; let i=index">
    <ul>
       <li>{{item.date}}</li>
    </ul>
    <div *ngFor="let survey of item.surveys ; let j=index">
    <ul>
      <li>{{survey.br_0}} </li>
    </ul>
  </div>
  </div>

1 Comment

it didn't work..nothing is display.. worked plnkr plnkr.co/edit/k2neX2DLtCnoDuLzhzvQ?p=preview

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.