Leveraging Angular Dragula without the need for RequireJS

I'm eager to incorporate Drag and Drop functionality into my Angular project with the help of the angular-dragula module (https://github.com/bevacqua/angular-dragula). However, it appears that this module heavily relies on RequireJS. My experience with RequireJS is limited to just a few sample applications in the past. Is there a simple way to disentangle RequireJS from this module?

The creator seems to believe that it's a straightforward process (https://github.com/bevacqua/angular-dragula/issues/23), and has dismissed similar queries without providing a clear explanation. As I analyze the code, I can't seem to figure out how to integrate the module without introducing RequireJS to my project (which I prefer not to do). Do I have no choice but to forego using this module or compromise by adding Require, or is there a method to utilize it without Require?

Answer №1

With the assistance of those who left comments (thank you all!), I was able to successfully make this work. There are a couple of key steps you need to take. First, I made the mistake of bundling this module with my other modules and attempting to call it. Unfortunately, that won't work as it requires initialization with a parameter (angular). Here's what you should do:

  1. Include a reference to angular-dragula.js (or its minified version) in your index.html page below where you declare angular but above where you create your app.
  2. When specifying the dependencies for your app, include angularDragula(angular) (without quotes).
  3. Utilize dragula just like you normally would. If you need to access the service, you can use the name angularDragula.

As an example, here is how I declared my app:

var app = angular.module('app', [
  'ngRoute',
  angularDragula(angular)
]);

To make a simple list draggable and droppable, here is the HTML code I used:

<div dragula='"bag-one"' dragula-model="vm.items">
    <div ng-repeat="item in vm.items">{{ item }}</div>
</div>

It's worth noting that I did not explicitly declare angularDragula anywhere, unlike in some examples. In those cases, the author required angular, created the angular variable, then required angular-dragula and created the angularDragula variable. This step isn't necessary if you're not using RequireJS, provided you load the scripts in the correct order.

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

The $digest function has reached its maximum of 10 iterations. Operation aborted

Why do I keep receiving an error message and my video tag reloads every time I attempt to click on it or use the scrubber bar? I've heard that this message appears when you modify a variable in the directive that the directive is watching. Even after ...

What is the procedure for turning off hover color on an href element?

Working on a website that utilizes MUI components, I have incorporated href into the Tab elements within the navigation bar. <Tab label={element} id={index} sx={{display: {xs: 'none', md: 'inherit'}}} href={`#${navElements[element ...

The jQuery AJAX function successfully executes, but the MySQL post deletion operation fails to take place

I am encountering an issue with this particular code. The Ajax code runs through to the end and then fades out the parent of the delete button. Below is the code for the delete button, post, and Ajax: <?php include('php/connect.php'); ...

Binding text inputs in Laravel Vue.js does not work

I am working on building a basic edit application for a post using Laravel. I am utilizing Vue.js 2 to bind the data, but I am encountering an issue where the data is not displaying as expected. When I use Vue's syntax, such as @{{ postData.title }}, ...

Interactive bar chart that updates in real-time using a combination of javascript, html, and

Current Situation: I am currently in the process of iterating through a machine learning model and dynamically updating my "divs" as text labels. My goal is to transform these values into individual bars that visually represent the values instead of just d ...

Tips for choosing Week Range values with Selenium WebDriver

Currently, I am working with Selenium WebDriver and I am trying to figure out how to select week range values from a dropdown menu at once. I have a dropdown called Period, which, when selected, automatically reveals additional dropdowns for From week and ...

Converting non-null values in a JSON object to null within an MVC Controller method

Take a look at the image below... The information displayed in the upper section shows the JSON data from my client that is being sent to the MVC Controller. I directly copied this from Chrome Dev Tools. In the lower part, you can see the actual data rec ...

VueJS Component has trouble refreshing the DOM content following an AJAX Promise

I've encountered issues updating data in my Vue application after an AJAX callback. I have previously resolved similar problems by using Vue.set, but for some reason, it's not working for me today. The only difference is that I am calling a serv ...

Issue with Jade not displaying external JSON data

I am struggling with a jade template that is supposed to display all possible solutions from the QPX Express search request: { kind: 'qpxExpress#tripsSearch', trips: { kind: 'qpxexpress#tripOptions', requestId: 'RwDOf6H ...

substitute bullet point list item with new element

Assuming I have a list: <ul class="ul-1"> <li class="li-1">xx -1</li> <li class="li-2">xx -2</li> <li class="li-3">xx -3</li> </ul> Then I store it as: var list = $('.ul-1').html(); In ...

Exploring an alternative perspective on successful login in angular.js

Today was the beginning of my project to convert a website to angular.js. The main page is served by index.html and includes ng-view for other views such as login and signup. Working closely with a backend developer, I have successfully integrated a rest c ...

The MeshBasicMaterial in THREE.js successfully renders, while the MeshLambertMaterial does not produce the desired outcome

In my current project, I've been working on creating a randomized sheet composed of arrays containing x, y, and z coordinates to draw triangles between points. You can see the outcome by clicking on this screenshot. Initially, I utilized MeshBasicMat ...

Having difficulty with the useState hook in a material ui functional component that integrates with Firebase

Currently, I am endeavoring to create a sign-up form utilizing a Material UI functional component. Within this form, I am aiming to trigger a signup event by using the "onClick" attribute attached to the sign-up button. My approach involves passing the ema ...

In order to add value, it is necessary to insert it into the text box in HTML without using the "on

example <input type="text" id="txt1" onChange="calculateTotal();" /> <input type="text" id="txt2" onChange="calculateTotal();" /> <input type="text" id="txt3" onChange="updateValue();" readonly/> <input type="text" id="txt4" onChange= ...

Foundation Unveil Modal hidden from view

I'm currently integrating modals using Foundation 5 in a Rails application. The issue I'm facing is that the modal only works when the page is not scrolled down. If you scroll to the bottom of the page and try to activate the modal by clicking ...

There seems to be an issue with the functionality of Array.filter when trying to use it with arrays

I am facing an issue with filtering branchId from an Array. Here is the code snippet and steps I have taken. const [branchID,setBranchID]=React.useState([]); const tempTwo=[ { branchId: "61b25e0ae177d62ce4cb3b47", bra ...

How can I upload a folder with subfolders and keep the structure intact?

I'm working on a form that allows me to upload a folder containing both files and subfolders with more files inside. I managed to upload the folder successfully, but when I check my directory, all the files are in one folder without the subfolders. My ...

What's the reason why Angular stops flickering with the use of "/" in href?

Recently, I've come across a peculiar issue in one of my web applications while using Angular's routeProvider as a template engine. The app functions properly, but the behavior seems inexplicable to me. The problem arises during page transitions ...

JavaScript HTML content manipulation

Why doesn't this code work? innerHTML cannot handle something so complex? <html> <head> <script type="text/javascript"> function addTable() { var html = "<table><tr><td><label for="na ...

Attempting to add an element to an array results in an endless cycle

Here is a jsfiddle example showcasing the issue, but proceed with caution as it contains an infinite loop that can cause the browser tab to slow down and eventually freeze when the console is opened: https://jsfiddle.net/evx1j6yf/1/ Array Data: days: [ ...