Angular CDK provides the drag interactions and visual sorting for lists; your application must update its data when a drop occurs. Install @angular/cdk, mark the list with cdkDropList and its items with cdkDrag, then handle cdkDropListDropped to keep the displayed order and backing data aligned.
Install and set up Angular CDK drag and drop
The drag-and-drop package is @angular/cdk/drag-drop. Angular’s guide shows adding the CDK with the Angular CLI, then importing the directives used by the component. See the Angular drag-and-drop guide for version-appropriate setup details.
As an Amazon Associate I earn from qualifying purchases.
-
From your project directory, run
ng add @angular/cdk.What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
In the component that owns the list, import
CdkDropListandCdkDragfrom@angular/cdk/drag-drop, using the import style supported by your Angular project.#1 Best Overall
-
Put
cdkDropListon the list container andcdkDragon each item. Bind the list’s(cdkDropListDropped)event to a component handler.
Angular’s current guide and API pages do not establish a release number in the captured content, so check the documentation matching the version installed in your project before relying on version-specific syntax.
Build a sortable list and update its data
A minimal standalone component can look like this. The key line is the call to moveItemInArray in the drop handler: CDK changes the interaction and visual sorting, but it does not reorder the application’s data model for you.
Recommended Free Tools
Rank #2
import { Component } from '@angular/core';
import {
CdkDrag,
CdkDropList,
CdkDragDrop,
moveItemInArray,
} from '@angular/cdk/drag-drop';
@Component({
selector: 'app-sortable-list',
standalone: true,
imports: [CdkDropList, CdkDrag],
template: `
<ul cdkDropList (cdkDropListDropped)="drop($event)">
@for (item of items; track item) {
<li cdkDrag>{{ item }}</li>
}
</ul>
`,
})
export class SortableListComponent {
items = ['First', 'Second', 'Third'];
drop(event: CdkDragDrop<string[]>) {
moveItemInArray(this.items, event.previousIndex, event.currentIndex);
}
}
The example uses Angular’s modern control-flow syntax; projects using a different template style can keep the same CDK directives and drop-handler logic while following their installed Angular version’s syntax. The event provides previousIndex and currentIndex, which identify the item’s old and new positions in the list. The CdkDragDrop API also documents the source and destination containers, pointer-over-container status, pointer distance and drop point, and the native mouse or touch event.
Move items between connected lists
Use cdkDropListConnectedTo when the destination lists are known, referencing another drop-list instance or its ID. If lists are created dynamically or the set is not known in advance, put them under cdkDropListGroup to connect the group automatically. An optional cdkDropListEnterPredicate can decide whether an item may enter a destination.
Connections permit drag-and-drop between lists; they do not transfer items in your application’s collections. Handle the event by using its previousContainer and container to identify the source and destination, then remove the item from the source array and insert it into the destination array. For example:
Rank #3
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(
event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex,
);
}
}
For this handler, bind each list’s backing collection through its cdkDropListData input so the event containers expose the arrays being updated. The Angular guide covers connected lists, groups, and list data handling.
Choose sorting, movement, and acceptance behavior
Angular CDK exposes several independent controls; use only the ones your interface needs. The CdkDropList API describes list-level configuration, while the CdkDrag API describes item-level options.
-
Orientation: A list is vertical by default. Set it to horizontal for a single-row collection. For a wrapping layout that sorts in more than one direction, use
mixedorientation. Mixed sorting moves elements in the DOM and does not animate sorting. -
Constrain movement: Lock an item to a horizontal or vertical axis with
cdkDragLockAxis, or configure the list’s axis lock when the constraint should apply to the list. -
Provide a handle: Add
cdkDragHandleto a designated element inside a draggable item when users should drag from a specific part rather than anywhere on the item.Recommended: Fix Windows Errors and Clear Junk Files in Minutes - Free Scan →Recommended: Crashes or Glitches? A Free Driver Scan Usually Finds the Culprit →Recommended: PC Feels Slow? A Free Scan Shows What's Dragging Windows Down →Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
Disable interaction: Disable an individual drag item, a list, or a handle when that control should not be draggable or should not accept sorting.
-
Control visual states: Customize the drag preview and placeholder to fit the interface while an item is in motion.
-
Set allowed destinations: Use entry predicates to determine whether a destination accepts an item, and sort predicates to restrict the indices where an item can land.
-
Adjust drag configuration: The drag API includes options such as a root element selector, boundary element, axis lock, and drag-start delay.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallSpecial offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Enable automatic scrolling in a scrollable container
If automatic scrolling fails while dragging items inside a scrollable element, add cdkScrollable to that container. The CDK needs the directive to detect and control the container’s scrolling during a drag; the official guide explains this requirement in its scrollable-container guidance.
Quick Recap
What to implement for each use case
| Need | CDK setup | Application responsibility |
|---|---|---|
| Reorder one list | cdkDropList, cdkDrag |
Reorder the array with moveItemInArray using the event indices. |
| Move items among a known set of lists | Connect lists with cdkDropListConnectedTo. |
Remove from the source collection and insert into the destination collection. |
| Move items among dynamic lists | Group lists with cdkDropListGroup. |
Update the relevant backing collections on drop. |
| Allow only certain destinations or positions | Use entry or sort predicates. | Keep the data update consistent with the accepted drop. |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




