Home Angular 10 Angular 10 Drag Drop Working Tutorial

Angular 10 Drag Drop Working Tutorial

by therichpost
9 comments
Angular 10 Drag Drop Working Example

Hello to all, welcome back to my blog. Today in this blog post, I am going to tell you, Angular 10 Drag Drop Working Tutorial.

Angular 10 Drag Drop

Angular10 came and if you are new then you must check below two links:

  1. Angular10 for beginners
  2. Angular10 Basic Tutorials

Friends now I proceed onwards and here is the working code snippet for Angular 10 Drag Drop Working Tutorial and please use carefully this to avoid the mistakes:

1. Firstly friends we need fresh angular 10 setup and for this we need to run below commands but if you already have angular 10 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

Guys you can skip this step this step if you already have angular 10 fresh setup:

npm install -g @angular/cli 

ng new angulardragdrop //Create new Angular Project

cd angulardragdrop  // Go inside the Angular Project Folder

ng serve --open // Run and Open the Angular Project

http://localhost:4200/ // Working Angular Project Url

 

2. Now friends, here we need to run below commands into our project terminal to install drag drop  modules into our angular application:

npm install jquery --save // Install Jquery

npm install jquery-ui-dist // Install Jquery UI

ng serve

 

3. Now friends, here we need to add below  into our angular.json file to get modules styles and scripts:

...
"styles": [
              
              "node_modules/jquery-ui-dist/jquery-ui.min.css"
            ],
"scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/jquery-ui-dist/jquery-ui.min.js"
]
...

 

4. Now friends we need to add below code into src/app/app.component.html file:

...
declare var $ :any;

export class AppComponent {
  ...
  ngOnInit() {
  	$( "#sortable1, #sortable2" ).sortable({
        connectWith: ".connectedSortable"
       }).disableSelection();
  }
}

 

5. Now friends we need to add below code into src/app/app.component.html file:

<ul id="sortable1" class="connectedSortable">
  <li class="ui-state-default">Item 1</li>
  <li class="ui-state-default">Item 2</li>
  <li class="ui-state-default">Item 3</li>
  <li class="ui-state-default">Item 4</li>
  <li class="ui-state-default">Item 5</li>
</ul>

<ul id="sortable2" class="connectedSortable">
  <li class="ui-state-highlight">Item 1</li>
  <li class="ui-state-highlight">Item 2</li>
  <li class="ui-state-highlight">Item 3</li>
  <li class="ui-state-highlight">Item 4</li>
  <li class="ui-state-highlight">Item 5</li>
</ul>
 <style>
  #sortable1, #sortable2 {
    border: 1px solid #eee;
    width: 142px;
    min-height: 20px;
    list-style-type: none;
    margin: 0;
    padding: 5px 0 0 0;
    float: left;
    margin-right: 10px;
  }
  #sortable1 li, #sortable2 li {
    margin: 0 5px 5px 5px;
    padding: 5px;
    font-size: 1.2em;
    width: 120px;
  }
  </style>

 

Now we are done friends. If you have any kind of query or suggestion or any requirement then feel free to comment below.

Note: Friends, I just tell the basic setup and things, you can change the code according to your requirements. For better understanding must watch video above.

I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad.

Jassa

Thanks

You may also like

9 comments

Selva January 19, 2021 - 7:19 am

Hello Ajay
In my project I’m creating fields from form builder so how can I use drag & drop for the created fields.
Regards
Selva

Reply
Ajay Malhotra January 19, 2021 - 7:21 am

Hi, which npm plugin you use for form builder?

Reply
Selva January 19, 2021 - 7:35 am

I used angular forms for my builders.
(import { FormBuilder, FormGroup, FormArray, Validators } from ‘@angular/forms’;)

Reply
Selva January 19, 2021 - 7:33 am

I used angular forms for the builders
(import { FormBuilder, FormGroup, FormArray, Validators } from ‘@angular/forms’;)

Reply
Ajay Malhotra January 19, 2021 - 7:37 am

Okay, you want to user form via form builder input fields drag drop?

Reply
Selva January 19, 2021 - 8:13 am

yes

Reply
Ajay Malhotra January 19, 2021 - 8:14 am

Great and I will make post and video on this.

Reply
selva January 19, 2021 - 8:19 am

Thanks Ajay.

Ajay Malhotra January 19, 2021 - 8:31 am

Welcome 🙂

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.