I have a form array inside a formbuilder and i am dynamically changing forms, i.e. on click load data from application 1 etc.
The issue i am having is that all the data loads in but the data in the formarray stays and just concats the old items with new.
How do I make the formarray to only have the new array and hide the previous array. i am creating an array form using angular2.
working plnkr of my project
The following will do what you want, but as per discussed elsewhere, here is no possibility to revisit the other form elements, that requires a little more tinkering :)
Just set a condition that checks whether the object is the last item in the formArray, and if it is, it displays only that object.
So where you are iterating the objects array add the following condition:
<div *ngFor="let object of myForm.controls.objects.controls; let i=index">
<div [formGroupName]="i" *ngIf="i === myForm.controls.objects.controls.length -1">
Add these conditions inside the formArrays in the survey tab.
Forked