How can I ensure that a DIV dropped in a specific location remains stationary when implementing Angular's draggable droppable feature?

I'm currently using the Angular draggable droppable demo found at this link

In the image below, I have Divs that can be dragged. What I want to achieve is when I drag DIV 3 onto DIV 1, I want DIV 3 to stay in place and the other DIVs to slide down accordingly.

https://i.sstatic.net/aKybK.png

Here's a snippet from my dragdrop.component.ts file:

import { Component, OnInit, NgModule } from '@angular/core';
import {DragAndDropModule} from 'angular-draggable-droppable';

@Component({
  selector: 'app-dragdrop',
  templateUrl: './dragdrop.component.html',
  styleUrls: ['./dragdrop.component.css']
})
export class DragdropComponent implements OnInit {
droppedData: string;

  constructor() { }

  ngOnInit() {
  }

  dragEnd(event) {
    console.log('Element was dragged', event);
  }

}

And here's part of my dragdrop.component.html code:

<br><br>
<div mwlDraggable (dragEnd)="dragEnd($event)">Drag DIV  1</div>
<br><br>
<div mwlDraggable (dragEnd)="dragEnd($event)">Drag DIV  2</div>
<br><br>
<div mwlDraggable (dragEnd)="dragEnd($event)">Drag DIV  3</div>

    <div
      (drop)="this.droppedData = $event.dropData">
      <span [hidden]="!droppedData">Item dropped here with data: "{{ droppedData }}"!</span>
    </div>

Answer №2

If you're looking to create a user-friendly drag and drop application in Angular, I highly recommend utilizing the convenient plugin from Angular Material called cdk.

For more information on how to implement this feature, visit: https://material.angular.io/cdk/drag-drop/overview

I hope this suggestion proves helpful for your project.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigating to another component using the selected value from a select box in Angular 2

I have a select box with the following code: <select class="form-control" id="location" required [(ngModel)]="locations" name="location" #location="ngModel" (change)="getResult($event.target.value);"> <option *ngFor="let loc ...

What are the best practices for incrementing an integer property's value in Mongoose while also applying specific restrictions?

Within my studentSchema, there is a property called pass with a default value of 0. I am looking to increment this value by 1 whenever a user creates a new pass. pass: { type: Number, default: 0, }, ...

Using PHP loops to incorporate unique Jquery functionalities

I'm working on developing a basic food cart with size options such as small, medium, large, and extras like cheese, onions, and chili's. My script calculates the amounts, but I'm struggling to make each call for the script unique as it is c ...

tsconfig issues with compilation and testing

Here is the configuration in my tsconfig.json { "compilerOptions": { "noImplicitAny": true, "declaration": false, "strict": true, "strictNullChecks": false, "target": "E ...

Using the spread operator in ES6 allows for arguments to be placed in a non-con

When working in nodeJS, my code looks like this: path = 'public/MIN-1234'; path = path.split('/'); return path.join( process.cwd(), ...path); I was expecting to get: c:\CODE\public/MIN-1234 but instead, I got: `‌publ ...

Systemjs running with Angular2 is causing 503 errors

I have developed a basic Angular2 app that does not make any external calls to resources. It consists of approximately 10 components, each with its own HTML and CSS files. I utilize gulp to generate a distribution package and deploy it to a testing environ ...

Running multiple instances of setTimeout() in JQuery

I'm looking for a way to delay the execution of 10 lines of independent jQuery code with 2 seconds between each line. I initially tried using setTimeout() on each line, but is there a more elegant solution for this scenario? The jQuery DELAY method do ...

app.use not functioning properly within a class in Express

Currently, I am in the process of constructing a WebServer class with the capability to create either an HTTP or HTTPS express webserver. The primary objective of the abstract class is to establish some defaults for the express server. The child class that ...

"Enhance your HTML code by inserting clickable hyperlinks within a for loop

I am currently working on a Flask web app that generates an HTML table using static JSON data. The data is correctly displayed in the table, but I am facing an issue with adding hyperlinks to one of the columns that contain links to other websites. Despite ...

Is there a way to dynamically update the content of <li> tag with values from an array every x seconds

I am trying to create a li list using jQuery that will update every 2 seconds with new content, similar to game news updates. However, I'm encountering an issue during the first cycle where it skips the second item in the array. The subsequent cycles ...

What is the best way to send a value through an AJAX request?

My ajax update function is not working in the code below. How can I solve this issue? The edit method in my code is functioning properly. For example, the value is being passed in this code snippet: var name = row.find(".ContactPersonName").find("span"). ...

NodeJS not recognizing global variable causing it to return undefined

Can a global variable be defined in a node.js function? I wish to use the variable "ko" (declared in the getNumbers function) in other functions function getNumbers(callback) { result = cio.query("SELECT numbers FROM rooms WHERE durum='1'", ...

How to include a key-value pair to a JSON object within an array using JavaScript

I am looking to include the following functionality in the JSON data provided below: "Check if the key name default exists, and if it does, add another key within the same object => ("pin" : 91)." I have attempted to achieve this using the code snippet ...

How can I initiate an AJAX POST request over HTTPS?

Despite my efforts, I am consistently encountering a 404 error when attempting to make an Ajax POST request. The specific error message reads: "GET 404 (Not Found)." Could this issue be related to the site's use of https? Below is the code snippet t ...

Using remote: true within a modal does not function as expected

Having a form with remote: true is working as expected when on the form page. However, encountering issues when attempting to use the form within a modal. There are 2 scenarios: form_for(@report, remote: true, method: 'post') This throws an e ...

Angular 10 edit mode issue: Unable to set selected value in dropdown

Why is the value from the database not selected in the edit mode of the form? Even though I am getting the correct value in 'service.formData.SalesRepId', it is not being selected. Is there something I am overlooking? https://i.sstatic.net/DLtfr ...

PHP API is returning the entire object, rather than just the message

I recently developed a REST API using PHP for data insertion. However, when I try to display the message in my AJAX success response, all I get is a series of objects instead. Here is my PHP code snippet: if(mysqli_query($connection , $ins)){ echo jso ...

Why is it that my service in the Angular project doesn't fetch data after I make changes and reload the page?

When a user selects a customer, I have a method that fetches the customer's ID from the database and saves it to local storage. However, if I make changes to my code and refresh the page after selection, it doesn't fetch the customer ID. How can ...

Utilize the apostrophe-images-widgets custom widget by calling apos.attachments.url function twice

I'm currently working on creating a unique layout using the apostrophe-images-widgets for my website. I've managed to override the html template at the project level in lib/modules/apostrophe-images-widgets/views/widget.html. The problem I'm ...

Refining the Union Type of Sets and Arrays for the find function

Here is the data model representation: A person's daily data structure interface FetchDocument { Date : number, Hours : number, } Grouping collection of these data points type Data_Array = Set<FetchDocument> | FetchDocument[] interfac ...