Drag Drop Zone
Overview
The DragDropZoneDirective makes an element both draggable and droppable, allowing it to be moved and to act as a valid drop target for other items.
It extends the DragDropZone base class to combine drag-and-drop logic in a single directive.
Multiple instances can be used on the same page, each managing independent drag-drop interactions.
Import
import { DndModule } from 'ngx-builder-dnd';Selector
ngxDragDropZone
API Reference
Type Parameters
| Name | Description |
|---|---|
T extends DndTreeItem | Defines the type of draggable and droppable item handled by the directive. |
Inputs
| Name | Default | Description |
|---|---|---|
ngxDragDropZone: T | - | The draggable and droppable item instance. |
allowedItems: Array<string | number> | - | Restricts which item types can be dropped onto this element. |
customDragHandleElement: HTMLElement | - | Custom element to use as the drag handle instead of the host container. |
previewComponent: Type<PreviewComponent<T>> | - | Component class used to render a custom drag preview for this item. |
useBrowserPreview: boolean | false | If true, the directive uses the browser's native drag preview instead of a custom one. |
Lifecycle Hooks
These optional protected methods allow subclasses to attach logic to key lifecycle stages without overriding Angular hooks directly:
| Hook | Called During |
|---|---|
protected onInit() | ngOnInit |
protected afterViewInit() | ngAfterViewInit |
protected onDestroy() | ngOnDestroy |
Example
<div
[ngxDragDropZone]="myItem"
[allowedItems]="['text', 'image']"
>
Draggable and droppable item
</div>
See Also
- Base Drop Zone - Provides shared logic for drop-zone implementations.
- Drag Drop Zone Directive - Enables combined drag and drop behavior on an element.