Search code examples
angularangular-cdk

Angular 8 cdk get index


I am working on Angular CDK drag and drop, when I am dropping an item into the list I can get index from previous list and the new index it has, how I will get the index of the item above which the handle is dropped.


Solution

  • If my understanding is right, you need the index of item that is below the dropped item.

    For that you can use

    for index of below item.

    belowItemIndex=currentIndex+1;
    

    for Index of above item

    aboveItemIndex=currentIndex-1;
    

    Hope it helps!