Angular Dragula and ng-repeat $index

I have an ng-repeat of rows. I set them up so you can reorder them with drag-and-drop using Angular Dragula. This works fine, but the ng-repeat $index remains the initial value for each item after dragging. See screen captures below before and after a drag of the "Recipient" row.

Is there a way to update the index? I also want to re-order the menu with javascript, with that button in each row, but for that to work I need to get the current $index (and decrement/increment it) and that won't work if the index is incorrect like this.

Before Drag

enter image description here

After Drag

enter image description here


ANSWERS:


Try to add in ng-repeat track by $index.


For what it's worth, this is the answer:

 <div class="table-cards-body" dragula="'first-bag'" dragula-model="home.quickReceiveFields">

      <div class="table-cards-row drag-item" ng-repeat="field in home.quickReceiveFields track by $index">
        <div class="one">{{field.name}}</div>
        <div class="two">{{field.type}}</div>
        <div class="three">{{field.default}} {{$index}}</div>
        <div class="four"><input type="checkbox" ng-model="field.display"></div>
        <div class="five"><input type="checkbox" ng-model="field.retain"></div>
        <button class="btn btn-default btn-xs" ng-click="home.moveItemUp($index)">^</button>
      </div>

 </div>

Despite what the docs say on the angular-dragula site, you need to put the dragula-model attribute on the container into which you put the repeating items. Not the ng-repeat itself.



 MORE:


 ? Dragula Drag only wanted elements
 ? angular2 Dragula css cursor grab/grabbing not working
 ? ng2-dragula group items in div
 ? Adding Dragular to Angular2 Application: document is not defined
 ? AOT error: require is not defined (caused by ng2-dragula library)
 ? Using ng2-dragula to drag and swap grid lists
 ? How to make it work: Dragula drag-and-drop on Meteor
 ? angular-dragular issue with dragular-model
 ? Multiple containers with Dragula, but restrict items to only their container
 ? ng2-dragula style original element when copying