Like it says, I want to add an item to the middle of a FormArray. So, I have a FormArray and every FormArray item has a button to add a new FormArray item. However, it currently always adds it to the bottom. I want to add it right after the item that the button is clicked on.
<div *ngFor="let filter of filterArray; let i = index" [formGroupName]="i" >
<ng-select [items]="items1" bindLabel="name" formControlName="fc1"></ng-select>
<ng-select [items]="items2" bindLabel="name" formControlName="fc2"></ng-select>
<input type="text" formControlName="value" placeholder="Value">
<button type="button" (click)="addRow(i)">Add</button>
<button type="button" (click)="removeRow(i)"><i class="bi bi-x"></i></button>
</div>
So, if there are three items in the array and I click the Add button on the second item it should add the item immediately after the second item, not at the end of the list. Since the FormArray isn't and actual array, the splice
method doesn't work. Any relatively easy way to work with a form array like this?
.ts
file to check the logic behind this