Having trouble displaying items on an HTML page while utilizing an AngularJS drag and drop list library?

Currently trying to add a drag and drop feature to my project. Utilizing the angular-drag-and-drop-lists library, with a working demo available for reference. Despite no errors in the console, nothing is displaying on the HTML page. I did manage to render the list without the associated CSS by commenting out that code.

In need of assistance to resolve this issue and understand why the content isn't appearing on the HTML page.

HTML:

<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script>

        <script src="./script.js"></script>
        <script src="./angular-drag-and-drop-lists.js"></script>
        <title>Document</title>
        <link rel="stylesheet" href="./style.css">
    </head>
    <body ng-app="demo">
        <div ng-controller="SimpleDemoController" class="simpleDemo">
            <ul dnd-list="list">
                <li ng-repeat="item in list" dnd-draggable="item"
                    dnd-moved="list.splice($index, 1)"
                    dnd-effect-allowed="move"
                    dnd-selected="models.selected = item"
                    ng-class="{'selected': models.selected === item}">
                    {{item.label}}
                </li>
            </ul>
            <!-- <ul ng-repeat="item in models.lists.A">
                <li>{{item.label}}</li>
            </ul> -->


        </div>
    </body>
</html>

Javascript

var demo = angular.module('demo', []);

var SimpleDemoController = function($scope) {

    $scope.models = {
        selected: null,
        lists: {"A": [], "B": []}
    };
    console.log($scope.models.lists.A, $scope.models.lists.B);
    
    // Generate initial model
    for (var i = 1; i <= 3; ++i) {
        $scope.models.lists.A.push({label: "Item A" + i});
        $scope.models.lists.B.push({label: "Item B" + i});
    }

    // Model to JSON for demo purpose
    $scope.$watch('models', function(model) {
        $scope.modelAsJson = angular.toJson(model, true);
    }, true);

};

demo.controller('SimpleDemoController', SimpleDemoController);

css

.simpleDemo ul[dnd-list] {
    min-height: 42px;
    padding-left: 0px;
}
.simpleDemo ul[dnd-list] .dndDraggingSource {
    display: none;
}
.simpleDemo ul[dnd-list] .dndPlaceholder {
    background-color: #ddd;
    display: block;
    min-height: 42px;
}

.simpleDemo ul[dnd-list] li {
    background-color: #fff;
    border: 1px solid #ddd;
    border-top-right-radius: 4px;
    border-top-left-radius: 4px;
    display: block;
    padding: 10px 15px;
    margin-bottom: -1px;
}
.simpleDemo ul[dnd-list] li.selected {
    background-color: #dff0d8;
    color: #3c763d;
}

Answer №1

To successfully implement drag and drop functionality in your Angular application, make sure to include "dndLists" in the demo variable that defines your angular module.

var demo = angular.module('demo', ["dndLists"]);

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

Displaying current location on Google maps with generated code and adding a new marker by clicking in PHP: Firefox

I am currently working on a code that will display a marker at the current location and also add a new marker whenever the screen is touched or clicked. I have been trying to make it work with the code I found online, but it has been a bit of a challenge ...

Discover the method for retrieving the value of a toggle-style checkbox

I am currently working with a toggle switch checkbox and I need to extract its value using JavaScript or jQuery when the state changes. Based on this value, I aim to highlight the text of the label associated with the toggle switch, whether it's opti ...

Having trouble with Typescript accurately converting decimal numbers?

I am struggling with formatting decimals in my Typescript class. export myclass { deposit: number; } After converting my web API class to this Typescript class, my decimal amounts lose their additional zero. For example, 1.10 becomes 1.1. I want to keep ...

Positioning Text Beside an Image Inside a Bootstrap Grid Column

Just starting out with coding and seeking assistance with a layout inquiry related to bootstrap. I have an image and a paragraph nested within a column in an attempt to utilize the grid system in bootstrap. My goal is to have the image float to the left w ...

Adjust camera to align with the loaded object in Three.js

I've been struggling to center the camera around the model loaded through the stl loader. I've tried adjusting variables and setting different positions for the mesh and camera, but the camera still isn't centered on the design! Here's ...

What is the most effective method for merging two arrays in JavaScript?

Can a function be created to generate an array like the following? ["0-AA", "0-BB", "1-AA", "1-BB", "2-AA", "2-BB", "3-AA", "3-BB"] This particular function combines two array ...

Tips for preventing a child div from moving when scrolling towards it and creating an internal scroll with a smooth animation using either JavaScript or jQuery

Looking to add scrolling functionality with animation to a child div on my webpage? Check out this example. I attempted using JavaScript's on scroll function, but it didn't work as expected. Currently, I have it set up to trigger on click of cer ...

Can anyone provide tips on utilizing the .parent() method to generate a button that is exclusively associated with a single <div> element?

I'm working with the FullCalendar jQuery plugin and I'm attempting to create a 'weekends' button that will toggle weekends in the calendar display. The challenge I'm facing is that I have multiple calendar views on the same page, a ...

What methods can be utilized to implement automatic location detection on a website using HTML5?

For a web project I'm developing, there's a specific requirement where a button labeled "auto detect" needs to be included. When this button is clicked, the visitor should receive a popup displaying their location near a textbox. I have successfu ...

Using Firebase to connect and disconnect from state in React with Re-base

I'm encountering some issues with React and Firebase while using the re-base module. When attempting to retrieve content from Firebase across different components in my app, I run into a problem. On one component/"page," which is home, I have the abi ...

Receiving 'Unexpected end of input' error when using a string as a JavaScript function argument

I am trying to implement an ajax request function in my project. This is the code snippet I have: function Reject(id, scomment) { jQuery.ajax({ type: "POST", url: "reject.php", data: {id: id, Scomment: scom ...

When I try to use the mongoose find() function, I am receiving a Promise status of <Pending>

I recently developed a function to retrieve the list of all products stored in MongoDB using mongoose. However, when trying to log this information, I am unexpectedly getting a Promise instead. Below is the relevant code snippet: router.get('/', ...

Exploring Line-height CSS Properties in Different Web Browsers

I'm currently attempting to determine if there is a method to inspect each line element in a browser individually. Currently, when right-clicking on a line of text, it visualizes the entire paragraph. However, I am interested in visualizing each line ...

When generating dynamic text boxes, a new area is always allocated for each new set of dynamic text boxes that are created

<html> <head> <script src="jquery-1.10.2.min.js"></script> <script> function AddingTextBoxes() { var NumOfText=$("#NumOfTextBoxes").val(); $('#NewlyCreatedSe ...

Utilize Vue and webpack to seamlessly load images

Currently experimenting with the following: <img src="./src/assets/logo.png"></img> Or maybe this option: background-image: url("./src/assets/logo.png"); I have executed npm install [email protected] npm install file-loader --save-dev. ...

Optimal method for determining service availability

I am looking for a way to check if my service is currently available. Oddly, I receive success in the ajax() function even when attempting to access certain service methods that are turned off. Instead of receiving expected data, I am greeted with an htm ...

What is the best way to style an element within an array that uses special characters in its name within JSON format?

I am attempting to include a specific header in the request, but one of them contains special characters. Access-Control-Allow-Origin This header is necessary to ensure that the request can proceed without being blocked by CORS Code: const fetchData = as ...

How can I incorporate varying textures into an object using `TextureLoader.load`?

I'm interested in adding various textures to each side of a box, but I'm uncertain if using loader.load is the correct approach. Currently, my code looks like this: loader.load('img/brick.jpg', function ( texture ){ var boxGeometry ...

Controlling the behavior of React components in response to updates

I'm currently learning ReactJs and utilizing the ExtReact framework for my project. I have successfully implemented a grid with pagination, which is functioning well. I customized the spinner that appears during data loading and it works as expected ...

Ajax is able to fetch a JSON string, however it struggles to iterate through the successful data as an

My current project involves creating a graph using d3.js. I came across some php code that fits my needs perfectly. However, I am working with c# and Visual Studio, so I need to convert it into asp.net. For starters, I want to input some hardcoded sample d ...