[Fixed] Is there any way to access the current index in the CdkDragMove event object


I am using the Angular CDK drag-drop (Material UI) and I want to get the current index of the dragged item in the CdkDragMove event object. Can anyone guide me?


if you use *ngFor for iterating over list, you can use index variable of NgFor context.

<div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
  <div class="example-box" *ngFor="let movie of movies; let i = index" 
  (cdkDragMoved)="move($event, i)" cdkDrag>{{movie}}</div>

Leave a Reply

(*) Required, Your email will not be published