I am facing an issue with sorting an array based on a numeric control value inside a formGroup nested in another array:
const toSort = [
['key2', FormGroup: {controls: {order: 2}}],
['key1', FormGroup: {controls: {order: 1}}]
]
The goal is to display the controls in the form in a specific order. I have successfully sorted the array, but after submitting the form, the last control is not updating with the new value. However, when the controls are automatically sorted alphabetically, all values update correctly.
This is the sorting function I used:
toSort.sort((val1, val2) => {
return val1[1].controls.order.value - val2[1].controls.order.value;
});
Any insights on why this behavior is happening?