I need to sort an array based on a control value (number type) from a formGroup inside another array:
const toSort = [
['key2', FormGroup: {controls: {order: 2}}],
['key1', FormGroup: {controls: {order: 1}}]
]
I need to sort them so that a form shows the controls in that specific order. I have been able to sort it but somehow when I do it, when I submit the form the last control is not updating with the new value (the rest do). If I undo the sorting and the controls sort automatically in alphabetic order all the controls update their values correctly.
This is how I sorted the array:
toSort.sort((val1, val2) => {
return val1[1].controls.order.value - val2[1].controls.order.value;
});
Any idea why is not working?