fatlinesofcode / ngDraggable

Drag and drop module for Angular JS
MIT License
631 stars 400 forks source link

onDropComplete cannot get the element that I dropped into #248

Open treidio opened 8 years ago

treidio commented 8 years ago

how can I get the drop element passed into ondropcomplete? stumped for days.. it seems a recuring question thx in advance

treidio commented 8 years ago

got it. I know its bad to access the dom element directly, but I'm dropping onto a scrolling section so I have to change the draggables parent on drop so it moves with the scrolling, yet remains a draggable so I can drag it to another position

first I do this ~ line 242 - add the scope.el assignment

link: function (scope, element, attrs) {
                    scope.value = attrs.ngDrop;
                    scope.el = element;
                    scope.isTouching = false;

and then ~ line 318 I add the $dropscope to the object.

onDropCallback(scope, {$data: obj.data, $event: obj, $dropscope : scope, $target: scope.$eval(scope.value)});

and then in the html ng-drop-success="onDropComplete($data,$event,$dropscope)"

and finally in my js

     $scope.onDropComplete=function(data,event,dropscope){
               console.log(dropscope.el);    
    };

hope this helps someone, if theres a better way, let me know.

cheers