It appears that there may be a syntax error present in my code.
Within my controller, I have a set of 4 functions: adding a new item, deleting the current item, moving an item backward (up) in the array, and moving an item forward (down) in the array.
All of these functions are functional, except when attempting to move the first item down in the array.
vm.maxChoices = 6;
vm.addNewChoice = function(arr) {
var newItemNo = arr.length + 1;
arr.push({
'id': 'choice' + newItemNo
});
};
vm.deleteChoice = function(arr, index) {
arr.splice(index, index);
};
vm.moveUpChoice = function(arr, index) {
var currItem = index;
if (currItem>0) {
arr.splice(currItem-1,0, arr.splice(currItem, currItem)[0]);
}
};
vm.moveDownChoice = function(arr, index) {
var currItem = index;
var newPosition = index+1;
if (currItem < arr.length) {
arr.splice(newPosition,0, arr.splice(currItem, currItem)[0]);
}
};
vm.showAddChoice = function(choice,arr) {
return arr.length !== vm.maxChoices;
};
My question is, what mistake have I made with the moveDownChoice function?
You can see a working example here: http://plnkr.co/edit/WPdnmYbDSXC0LsbeMduM?p=preview
Feel free to create 3 or 4 rows, input data into the fields to observe the movement. You will notice that you can move #2 to #3 etc., but trying to move the first item down results in creating a NEW item instead of moving it to #2.