How To Drag And Drop Items Using Angular(v2 to v14)

How to Drag & Drop Items using Angular(v2 to v14)

Step 1

Create the angular app and install ng-drag-drop

npm i ng-drag-drop

Step 2

Put required CSS and js file into index.html file, See below HTML code,

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <title>Drag and Drop by RG</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""> 
    <script src=""></script>

Step 3

Now import the NgDragDropModule in the app.module.ts file

app.module.ts file

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NgDragDropModule } from 'ng-drag-drop'; //Import NgDragDropModule module

  declarations: [
  imports: [
  providers: [],
  bootstrap: [AppComponent]
export class AppModule { }

 Step 4

Now put the drag and drop code into the app.component.ts file as shown below

import { Component, ViewChild  } from '@angular/core';
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
export class AppComponent {

  constructor() { }
  // Here I have used the static employeeList you can use dynamic employeeList
  employeeList = [
    { empName: "Rajesh Gami", designation: "FullStack Developer" },
    { empName: "Subhash Saliya", designation: "FullStack Developer" },
    { empName: "Sirish Upadhyay", designation: "UI/UX Developer" }

  droppedEmployeeList = [
    { empName: "Jaydeep Patel", designation: "QA" },
    { empName: "Moin Bloch", designation: "Web Developer" },

  addDragDropItem(e: any) {
    const index = this.employeeList.indexOf(e.dragData);
    if (index > -1) {
      this.employeeList.splice(index, 1);

  removeDragDropItem(e: any) {
    const index = this.droppedEmployeeList.indexOf(e.dragData);
    if (index > -1) {
      this.droppedEmployeeList.splice(index, 1);

In the component I have used static employee list just for the example, So you can use dynamic list as your requirement.

Step 5

So now need to put the HTML code into the app.component.html file. Let's put the drag and drop HTML code

  <h3>Move Employee via Drag Drop</h3>
  <div class="row">
      <div class="col-sm-3">
        <div class="panel m-height panel-default" droppable (onDrop)="removeDragDropItem($event)">
          <div class="panel-heading">Drag and drop items here</div>
          <div class="panel-body">
            <li draggable *ngFor="let item of employeeList" [dragData]="item" class="list-group-item"> {{item.empName}} <small> ({{item.designation}})</small>

      <div class="col-sm-3">
        <div class="panel m-heightpanel-default" droppable (onDrop)="addDragDropItem($event)">
          <div class="panel-heading">Drag and drop items here</div>
          <div class="panel-body">
            <li *ngFor="let item of droppedEmployeeList" class="list-group-item" draggable [dragData]="item">{{item.empName}} <small> ({{item.designation}})</small></li>

Step 6

This is last step to add some basic CSS in the style.scss/style.css file

/* You can add global styles to this file, and also import other style files */
.drag-border {
  border: #d4000b dashed 2px;

.drag-handle {
  cursor: move;
  cursor: grab;}
.drag-handle:active {
  cursor: grabbing;

.drag-hint-border {
  border: #006d02 solid 2px;
.drag-over-border {
  border: #000000 solid 2px;

.drag-transit {
  border: #008bad solid 2px;
  min-height: 100px;

Let's save the code and run the application


How to Drag & Drop Items using Angular(v2 to v14)

You can move employee from one box to another box, Let's move Rajesh Gami from the left box to the right side box

How to Drag & Drop Items using Angular(v2 to v14)

Simply drag the employee using your mouse click and drop it into the box.