How to Create simple drag and Drop in angularjs

后端 未结 8 1626
孤独总比滥情好
孤独总比滥情好 2020-11-29 16:55

I want to know how to do drag and drop by using AngularJs.

This is what I have so far:



        
8条回答
  •  我在风中等你
    2020-11-29 17:24

    Modified from the angular-drag-and-drop-lists examples page

    Markup

    • {{item.label}}

    Angular

    var app = angular.module('angular-starter', [
        'ui.router',
        'dndLists'
    ]);
    
    app.controller('MainCtrl', function($scope){
    
        $scope.models = {
            selected: null,
            lists: {"A": [], "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);
    });
    

    Library can be installed via bower or npm: angular-drag-and-drop-lists

提交回复
热议问题