Fork me on GitHub

Angular Drag and Drop

A Native ( without jquery ) Drag and Drop directive for AngularJS using HTML5 Drag and Drop

Directives


ui-draggable

directive in module ngDragDrop

The ui-draggable attribute tells Angular that the element is draggable. ui-draggable takes an expression as the attribute value. The expression should evaluate to either true or false. You can toggle the draggability of an element using this expression.

Additional Attributes

drag

The drag property is used to assign the data that needs to be passed along with the dragging element.


on-drop-success

The on-drop-success attribute takes a function. We can consider this to be an on-drop-success handler function. This can be useful if you need to do some post processing after the dragged element is dropped successfully on the drop site.

NOTE : This callback function is only called when the drop succeeds.
You can request the drag-end event ( very similiar to requesting the click event in ng-click ) by passing $event in the event handler.


Usage

...

Details

Param Type Details
ui-draggable Expression that should be evaluated. The given expression should resolve to true or false.
drag Takes any JSON convertable $scope variable.
on-drop-success Takes any $scope function. Can also pass $event.
drag-channel Takes a string that can be used as the channel name for the dragging operation. Default channel is "defaultchannel"


Events

On start of dragging an Angular Event ANGULAR_DRAG_START is dispatched from the $rootScope. The event also carries carries the information about the channel in which the dragging has started.

On end of dragging an Angular Event ANGULAR_DRAG_END is dispatched from the $rootScope. The event also carries carries the information about the channel in which the dragging has started.


ui-on-drop

directive in module ngDragDrop

The ui-on-drop attribute tells Angular that the element is a drop site. ui-on-drop takes a function as the attribute value. The function will be called when a valid dragged element is dropped in that location. A valid dragged element is one which has the same channel as the drop location.

NOTE : This callback function is only called when the drop succeeds.
The ui-on-drop callback can request additional parameters. The data that is dragged is available to the callback as $data. Apart from this the drop event is exposed as $event.

Additional Attributes

drop-channel

The channel that the drop site accepts. The dragged element should have the same channel as this drop site for it to be droppable at this location.


drag-enter-class

The class that will be added to the the droppable element when a dragged element ( which is droppable ) enters the drop location. The default value for this is on-drag-enter


Usage

...

Details

Param Type Details
ui-on-drop Takes any $scope function. Can also pass $event and $data.
drop-channel The channel on which the drop has to listen for drag events.
drag-enter-class A class name that will be put on the droppable element when the dragged objects enters its boundaries.


Demo