I have a reactive form where I create the controls from my data model. Initially, everything is sorted by a datapoint called the "processingOrder" in numerical order.
Within my form array, I am using *ngFor to iterate over controls and store the index in a hidden form control. If I move a record up or down in my table, the index thats being applied to the hidden field should reflect the change in my model right?
<form [formGroup]="rulesForm" (ngSubmit)="onSubmit(form)">
<div formGroupName="ruleData">
<div formArrayName="rules">
<div *ngFor="let child of rulesForm.controls.ruleData.controls.rules.controls; let i = index">
<div formGroupName="{{i}}">
<input type="text" placeholder="Rule Name" formControlName="name"/>
<input type="text" placeholder="Rule Description" formControlName="description"/>
<input type="text" placeholder="Processing Order" formControlName="processingOrder"/>
<button class="button" (click)="move(-1, i)">Move Up</button>
<button class="button" (click)="move(1, i)">Move Down</button>
<!-- Why doesn't this update my model when it gets a new index? -->
<input type="hidden" formControlName="processingOrder" [value]="i">
</div>
</div>
</div>
</div>
<button type="submit">Submit</button>
</form>
I would have expected that in my plunker, the processing order numbers should always remain in the 1-5 order and each time a rule is moved up or down, the model is updated to the new index it received.