Situation

On the image you can see what I'm trying to to. Using an ng-repeat to dynamically add a row of inputfields when +step is clicked. The x removes a step and the up and down arrows move a step one place up or down.

I want the up arrow to be disabled when a step can't go higher and the down disabled when it can't go lower. So far when I've only added steps (and not removed) it works perfectly. However when I delete a step, the $index somehow isn't updated in the ng-disabled altough it seems updated when I print it.

Problem

Here's what I get after I delete the first step: image

As you can see, the down array is disabled. Although the printed index is 0, the index in the ng-disabled must still be 1.

HTML:

<div class="col-sm-2 nopadding"> <div class="btn-group btn-lg" role="group"> <!--move step up--> <button type="button" class="btn iconbutton " ng-click="" ng-disabled="{{$index}}==0"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span> </button> <!--move step down--> <button type="button" class="btn iconbutton " ng-click="" ng-disabled="{{$index}}==normal.length-1"><span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span> </button> <!--remove step--> <button type="button" class="btn iconbutton " ng-click="removeStep(step,'normal',0)"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> </button> </div> <p>index={{$index}}, length= {{normal.length}}</p> </div>

remove function in the controller:

$scope.removeStep = function (item,flow,index) { if(angular.equals(flow,'normal')){ var i = $scope.normal.indexOf(item); $scope.normal.splice(i, 1); } if(angular.equals(flow,'alternative')){ var i = $scope.alternative[index].behavior.indexOf(item); $scope.alternative[index].behavior.splice(i, 1); } if(angular.equals(flow,'exceptional')){ var i = $scope.exceptional[index].behavior.indexOf(item); $scope.exceptional[index].behavior.splice(i, 1); }

};

Update: found a work-around

It's not as clean as working with $index, but I wrote a function in my controller which, given the item, returns the position of that item in the array. This works for all situations