angularjs-dragula icon indicating copy to clipboard operation
angularjs-dragula copied to clipboard

How to get drag and drop target and source

Open gautamgolakiya opened this issue 8 years ago • 8 comments

I have many card in which i have to put drag and drop. Now as matter of fact drag and drop is work perfect but how can i get the target and source of my block which is i am drag and drop.

The code looking something like this :

function TaskCtrl($scope, $http, dragulaService) { $scope.many = ['The', 'possibilities', 'are', 'endless!']; $scope.many2 = ['Explore', 'them'];

    $scope.$on('another-bag.drag', function (e, el){
         console.log('drag ' + $(el).html());
    });

   $scope.$on('another-bag.drop', function (e , el) {
         console.log('drop ' + $(el).html() + ' in ' + $(e).html() );
    });

});

gautamgolakiya avatar Jun 27 '16 06:06 gautamgolakiya

Hello,

Same question here, I have a List of JS object :

new = [{ 'title' : 'exemple', id : 1'}, { 'title' : 'exemple2', id : 2'}]

wich I bind with html :

<div class="container" dragula='"bag-one"' dragula-model='new'>
    <div class="ticket" ng-repeat="ticket in new track by ticket.ID" >
      {{ticket.Title}}
    </div>
  </div>

Then, I would like to retrieve the JS item wich has been moved in my controller :

$scope.$on('bag-one.drop-model', function (e, el, ticket) {
      //el is the HTML element,  I need the JS object here
    });

Is it possible?

Thx

J0hnRoger avatar Jul 06 '16 15:07 J0hnRoger

the same, , I would like to retrieve the JS item wich has been moved

gyerzh avatar Sep 02 '16 09:09 gyerzh

I am having the same issue any progress how can i get the js object?

fahimmahmoodmir avatar Nov 24 '16 17:11 fahimmahmoodmir

me too

xiyuyizhi avatar Feb 27 '17 09:02 xiyuyizhi

@bevacqua This would EXTREMELY helpful to everyone to add if possible. I see there is a pull request for this https://github.com/bevacqua/angularjs-dragula/pull/97

logan-jobzmall avatar Dec 13 '17 01:12 logan-jobzmall

Wow, am I missing something, or is it really not possible to access the angular scope of the dragged element? One workaround that may be useful is to use a ng-mousedown event handler on the draggable div, access the scope of the item in the ng-repeat, and set the values of a behind-the-scenes placeholder for the "current" scope properties to the properties sent via the ng-mousedown handler.

mg1075 avatar Jan 28 '18 07:01 mg1075

Here is my work around I use, until #97 is merged.

var lastDropIndex = -1;
$scope.$on( 'drag-things.drop', function ( event, el, container ) {
	lastDropIndex = Array.prototype.indexOf.call( container.children(), el[ 0 ] );
});
$scope.$on( 'drag-things.drop-model', function ( event, el, container ) {
	if ( lastDropIndex < 0 ) return;
	var drake = dragulaService.find( $scope, 'drag-things' ).drake;
	var containerIndex = drake.containers.indexOf( container[ 0 ] );
	var model = drake.models[ containerIndex ][ lastDropIndex ];
	
	debugger;
	
	lastDropIndex = -1;
});

HerbertMarshall avatar Jun 12 '18 14:06 HerbertMarshall

+1

leonardors95 avatar Sep 13 '18 20:09 leonardors95