1.1.2 • Published 7 years ago

angular4-drag-drop v1.1.2

Weekly downloads
423
License
MIT
Repository
-
Last release
7 years ago

Drag and drop attribute directive for Angular 4+

An angular4 module that exports a drag and a drop attribute directives.

Table of Contents

Installation

$ npm i angular4-drag-drop --save

Usage

To import the module into a module in which you wish to use the directive on components.

import { DragDropDirectiveModule} from "angular4-drag-drop";

This module exports two attribute directives, 'DragDirective' and 'DropDirective'. DragDirectve is used with a component from which you want to drag items, while DropDirective is used with the component in which you wish to drop items.

Both accept inputs for CSS class highlighting. If you do not pass a string then highlighting will be ignored. Both will emit the dragged item when it is dropped in the 'DroppableDirective' component or element.

'DragDirective' emits an event when dragging is started.

'DropDirective' emits events when a drag enters a drop element, leaves a drop element, and as stated above when an element is dropped.

DragDirective

<div *ngFor="let item of itemsToDrop" [dragDirective]='item' [dragHightlight]="'highlight'" (releaseDrop)="releaseDrop($event)" (startDrag)="startDrag(item)">
</div>

'dragDirective="item"' Applies the drag directive, and passes it an item.

'dragHighlight="'highlight'"' Passes a string to add a css class to the css class list of the element.

'(releaseDrop)="releaseDrop($event)"' Calls a function to act on the dragged item once it is dropped into the drop area.

'(startDrag)="startDrag(item)" Calls a function when the user starts dragging the item.

DropDirectve

<div dropDirective (dropEvent)="addDropItem($event)" (dropEventMouse)="dropEventMouse($event) (dragenterEvent)="dragEnter($event)" (dragleaveEvent)="dragLeave()" class="droppable" [dropHighlight]="'highlight'"  '(dragoverMouseEvent)'="dragoverMouse($event)">
</div>

'dropDirective' applies the directive to an element, making it a drop target. 'dropHighlight="'highlight'"' passes a string to add a css class to the css class list of the element.

'(dropEvent)="addDropItem($event)"' calls a function and passes the dropped item when an item is dropped into the drop element.

'(dropEventMouse)="dropEventMouse($event)"'. dropEventMouse is emitting the html drop event. From this you can get x,y cordinates of the drop etc. If you wish you can use this to get the dropped item as well: let droppedObject = JSON.parse(event.dataTransfer.getData('text')).

'(dragenterEvent)="dragEnter($event)"' calls a function and passes the dragged item when an item is dragged into the drop element.

'(dragleaveEvent)="dragLeave($event)"' calls a function and passes the dragged item when the item is dragged out of the drop element.

'(dragoverMouseEvent)="dragoverMouse($event)"' calls a function on the native element drag over function. This fires ever 350 millieseconds when an object is being dragged over the droppable box. It passes the dragover event.

##demo https://embed.plnkr.co/UOLION/

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.5.7

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago