# 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.

#### drag-handle-class

The class used to mark child elements of draggable object to be used as drag handle. Default class name is `drag-handle`.

NOTE: If attribute is not present drag handle feature is not active.

#### 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.

#### on-drop-failure

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

NOTE: This callback function is only called when the drop fails.
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 | Expression that should be evaluated. The given expression should resolve to true or false.
drag | variable | Takes any JSON convertable `$scope` variable.
drag-handle-class | string | Class name used to mark child elements of draggable object to be used as drag handle. If attribute is not present drag handle feature is not used. If attribute is present but have no value `drag-handle` used as default.
on-drop-success | function | Takes any `$scope` function. Can also pass `$event`.
on-drop-failure | function | Takes any `$scope` function. Can also pass `$event`.
drag-channel | string | 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.

When hovering a draggable element on top of a drop area an Angular Event `ANGULAR_HOVER` is dispatched from the `$rootScope`. The event also 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` and its channel as `$channel`. 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. It is possible to provide comma separated list of channels.

NOTE: Also special value of `drag-channel` attribute is available to accept dragged element with any channel value — `*`

#### drop-validate

Extra validation that makes sure that the drop site accepts the dragged element beyond having the same channel. If not defined, no extra validation is made.

NOTE: This callback function is called only if the channel condition is met, when the element starts being dragged

#### 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`

#### drag-hover-class

The class that will be added to the drop area element when hovering with an element. The default value for this is `on-drag-hover`

### Usage

...

### Details

Param | Type | Details
ui-on-drop | function | Takes any `$scope` function. Can also pass `$event`, `$data` and `$channel`.
drop-channel | expression | The channel on which the drop has to listen for drag events. Single value, comma separated list or special value `*` are possible
drop-validate | function | Takes any `$scope` function. Can also pass `$data` and `$channel`
drag-enter-class | string | A class name that will be put on the droppable element when the dragged objects enters its boundaries. Default class name is `on-drag-enter`.
| drag-hover-class | string | A class name that will be put on the drop area when an element is dragged onto it. Default class name is `on-drag-hover`.

### Demo