bevacqua / angularjs-dragula

:ok_hand: Drag and drop so simple it hurts
https://bevacqua.github.io/angularjs-dragula
MIT License
509 stars 109 forks source link

drop-model event not emitted #34

Closed victordelacruz closed 8 years ago

victordelacruz commented 8 years ago

Hello guys,

I'm trying out the angular version of dragula, and have this code in my view:

tbody( dragula='"badges-bag"' dragula-model='vm.badgeList' )

And this other code in my controller:

$scope.$on( 'badges-bag.drop-model', function( el, target, source ) {

The problem is that I'm not receiving the drop-modelevent. dragendand dropworks just fine. What could be the reason?

lobo-tuerto commented 8 years ago

The reason is that the model is setup at the directive's linking phase once. If later the model changes, this is not updated in the directive internals.

https://github.com/bevacqua/angular-dragula/pull/35 Fixes this.

Use example: Say you have an empty list (this is your model) that a later stage you want to load with an ajax call contents.

DanielSchuech commented 8 years ago

Isn´t it the problem that you just want to assign a new array to the dragula-model?

As described in other issues you are currently not allowed to do something like this:

vm.badgeList = newArray;

You need to hold the reference and just refill the current array

vm.badgeList.length = 0; //clears the array
newItemsArray.forEach(function(item) {
  vm.badgeList.push(item);
});
lobo-tuerto commented 8 years ago

Yes that's exactly the problem and this PR solves it.

DanielSchuech commented 8 years ago

I just wanted to let you know that its even now possible thorugh the refill.

The changes you ve done are looking good to me.

lobo-tuerto commented 8 years ago

Thanks for the observation Daniel, I have considered that option too, but found it a bit cumbersome on the user.

I'd like to work just as ng-repeat does, you point it to a new array and it works as expected, it considers the new values and goes through them.