For AI agents: the complete documentation index is available at https://gultyayev.github.io/ngx-virtual-dnd/llms.txt, the full documentation bundle is available at https://gultyayev.github.io/ngx-virtual-dnd/llms-full.txt, and this page is available as Markdown at https://gultyayev.github.io/ngx-virtual-dnd/api/services.md.

Services

All services are root singletons (providedIn: 'root').

DragStateService

Read-only signals describing the current drag. Inject it to react to drags anywhere in the app:

protected readonly dragState = inject(DragStateService);
@if (dragState.isDragging()) {
  <p class="hint">Drop the item into a list</p>
}
SignalTypeDescription
isDraggingbooleanA drag is in progress
draggedItemDraggedItem | nullThe dragged item, its element and size
draggedItemIdstring | nullID of the dragged item
sourceDroppableIdstring | nullList the drag started in
sourceIndexnumber | nullIndex the drag started at
activeDroppableIdstring | nullList currently targeted
placeholderIdstring | nullDeprecated, use placeholderIndex. END_OF_LIST while a list is targeted, otherwise null
placeholderIndexnumber | nullCurrent drop index
cursorPositionCursorPosition | nullPointer position
grabOffsetGrabOffset | nullOffset between the pointer and the item's top-left corner
initialPositionCursorPosition | nullPointer position at drag start
lockAxis'x' | 'y' | nullAxis lock of the current drag
isKeyboardDragbooleanThe drag was started with the keyboard
keyboardTargetIndexnumber | nullTarget index during a keyboard drag
wasCancelledbooleanWhether the last drag was cancelled
endedDragStateDragState | nullSnapshot of the last drag, taken just before it was reset

For styling a single list, the vdnd-droppable-active class is usually simpler.

AutoScrollService

Edge scrolling during drags. It is normally configured through component inputs.

MethodSignatureDescription
registerContainer(id, element, config?) => voidRegister a scroll container
unregisterContainer(id) => voidUnregister a scroll container
startMonitoring(onScroll?) => voidStart watching the pointer
stopMonitoring() => voidStop watching
isScrolling() => booleanWhether auto-scroll is active
getScrollDirection() => { x: number; y: number }Current scroll direction

Advanced services

These are exported for advanced customization. Most apps never need them.

ServicePurpose
PositionCalculatorServiceHit-testing and drop-index math over the lists rendered with vdndDroppable. refreshCandidates() re-reads the drop targets of an active drag.
ElementCloneServiceClones an element with its computed styles inlined, minus the root's placement and its focusability; used for the default preview.
KeyboardDragServiceKeyboard drag state.
OverlayContainerServiceThe body-level container that hosts the drag preview.