UNPKG

3.21 kBMarkdownView Raw
1# angular 10.0+ drag and drop
2
3[![Sponsorship](https://img.shields.io/badge/funding-github-%23EA4AAA)](https://github.com/users/mattlewis92/sponsorship)
4[![Build Status](https://travis-ci.org/mattlewis92/angular-draggable-droppable.svg?branch=master)](https://travis-ci.org/mattlewis92/angular-draggable-droppable)
5[![codecov](https://codecov.io/gh/mattlewis92/angular-draggable-droppable/branch/master/graph/badge.svg)](https://codecov.io/gh/mattlewis92/angular-draggable-droppable)
6[![npm version](https://badge.fury.io/js/angular-draggable-droppable.svg)](http://badge.fury.io/js/angular-draggable-droppable)
7[![Twitter Follow](https://img.shields.io/twitter/follow/mattlewis92_.svg)](https://twitter.com/mattlewis92_)
8
9## Demo
10
11https://mattlewis92.github.io/angular-draggable-droppable/
12
13## Table of contents
14
15- [About](#about)
16- [Installation](#installation)
17- [Documentation](#documentation)
18- [Development](#development)
19- [License](#licence)
20
21## About
22
23Observable powered drag and drop for angular 10.0+
24
25## Installation
26
27Install through npm:
28
29```
30npm install angular-draggable-droppable
31```
32
33Then use it in your app like so:
34
35```typescript
36import { Component, NgModule } from '@angular/core';
37import { DragAndDropModule } from 'angular-draggable-droppable';
38
39@NgModule({
40 declarations: [DemoApp],
41 imports: [DragAndDropModule],
42 bootstrap: [DemoApp],
43})
44class DemoModule {}
45
46@Component({
47 selector: 'demo-app',
48 template: `
49 <div mwlDraggable (dragEnd)="dragEnd($event)">Drag me!</div>
50 <div mwlDroppable (drop)="this.droppedData = $event.dropData">
51 <span [hidden]="droppedData">Drop here</span>
52 <span [hidden]="!droppedData"
53 >Item dropped here with data: "{{ droppedData }}"!</span
54 >
55 </div>
56 `,
57})
58class DemoApp {
59 droppedData: string;
60
61 dragEnd(event) {
62 console.log('Element was dragged', event);
63 }
64}
65```
66
67Note: if draggable elements are inside a scrollable element then you will need to add `mwlDraggableScrollContainer` as an attribute to the scrollable container.
68
69You may also find it useful to view the [demo source](https://github.com/mattlewis92/angular-draggable-droppable/tree/master/src/demo).
70
71## Documentation
72
73All documentation is auto-generated from the source and can be viewed here:
74https://mattlewis92.github.io/angular-draggable-droppable/docs/
75
76## Alternatives
77
78I wrote this library because I needed drag and drop whilst snapping to a grid. If you don't need this feature then I recommend checking out one of these other awesome drag and drop libraries:
79
80- [Angular CDK drag and drop](https://material.angular.io/cdk/drag-drop/overview)
81- [angular-skyhook](https://github.com/cormacrelf/angular-skyhook)
82- [ng-drag-drop](https://github.com/ObaidUrRehman/ng-drag-drop)
83
84## Development
85
86### Prepare your environment
87
88- Install [Node.js](http://nodejs.org/) and NPM (should come with)
89- Install local dev dependencies: `npm install` while current directory is this repo
90
91### Development server
92
93Run `npm start` to start a development server on port 8000 with auto reload + tests.
94
95### Testing
96
97Run `npm test` to run tests once or `npm run test:watch` to continually run tests.
98
99### Release
100
101```bash
102npm run release
103```
104
105## License
106
107MIT