angularjs-dragula
angularjs-dragula copied to clipboard
How to get drag and drop target and source
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() );
});
});
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
the same, , I would like to retrieve the JS item wich has been moved
I am having the same issue any progress how can i get the js object?
me too
@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
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.
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;
});
+1