I have an array called list
bound to the current application scope $scope
that is a user order-able list of UI components. When clicking the up / down arrays these functions are responsible for moving the element by re-inserting it in the correct place.
$scope.moveUp = function(index)
{
if (index === 0) {
return;
}
$scope.list.splice(index - 1, 0, $scope.list.splice(index, 1)[0]);
};
$scope.moveDown = function(index)
{
if (index === $scope.list.length - 1) {
return;
}
$scope.list.splice(index + 1, 0, $scope.list.splice(index, 1)[0]);
};