To create a template without using ng-repeat and pass data to $scope when using angular-drag-and-drop-lists, you can manually construct the HTML template and populate the data in the controller. angular-drag-and-drop-lists is an AngularJS library that allows you to create sortable, draggable lists without relying on ng-repeat.

Here's how you can achieve it:

  1. HTML Template: In your HTML file, create the template without ng-repeat and define the draggable and sortable elements using the provided directives from angular-drag-and-drop-lists. For example:

    html
    <div dnd-list="list"> <div dnd-draggable="item" dnd-effect-allowed="move" dnd-moved="removeItem(list, item)" ng-repeat="item in list"> {{ item }} </div> </div>

    This template creates a draggable list without using ng-repeat.

  2. Controller: In your AngularJS controller, define the $scope.list variable and populate it with the desired data. For example:

    javascript
    angular.module('myApp', ['dndLists']) .controller('MyController', function($scope) { $scope.list = ['Item 1', 'Item 2', 'Item 3']; $scope.removeItem = function(list, item) { var index = list.indexOf(item); if (index !== -1) { list.splice(index, 1); } }; });

    In this example, the $scope.list array contains the data that will be displayed in the draggable list. The removeItem function is used as the callback for when an item is moved/dragged and dropped to remove the item from the list.

  3. AngularJS App Initialization: Make sure to initialize your AngularJS app with the myApp module, which includes 'dndLists', and associate it with the HTML element where the template is defined.

    html
    <html ng-app="myApp"> <body ng-controller="MyController"> <!-- Your HTML template here --> </body> </html>

By manually constructing the template and populating the data in the controller, you can create a draggable list without using ng-repeat and still have control over the data that is displayed in the list. The angular-drag-and-drop-lists library provides additional directives and features to customize the behavior and appearance of the draggable lists.

Remember to include the necessary angular-drag-and-drop-lists script in your HTML file and ensure that the module is properly initialized in your AngularJS app.

Have questions or queries?
Get in Touch