angularangular-materialangular-dragdrop

Angular drag and drop, exit event, get data of removed item


I'm trying to get value or index of the item removed from the source list using the "cdkDropListExited" event. I do see the event getting fired but the "event.item.data" keeps coming as "undefined".

How can I get the value or index of a list item as soon as it is moved from a drop container into another one.

Demo/Example here


Solution

  • Well, that is simply beause you're not assigning any data to you cdkDrag.

    Take a look at the docs here and look for cdkDragData.

    So, in your code it would like this:

    <div class="example-box" *ngFor="let item of todo" cdkDrag [cdkDragData]="item">{{item}}</div>