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

Fix model watcher #41

Closed jameswyse closed 8 years ago

jameswyse commented 8 years ago

After upgrading to v1.1.9 I started getting an error when moving items:

TypeError: Cannot read property 'splice' of undefined at applyDrop (service.js:42)

This only occurs when there are multiple instances of the directive using the same bag, but with different dragulaModel values, such as when using a nested ng-repeat.

After some investigation I found this was due to a bug in the $watch expression (introduced in v1.1.7 by #35) which was basically not checking if the model was actually in the array before calling splice; causing the last model in the array to be replaced every time. This PR checks for that and calls push instead when the model isn't found.

luckylooke commented 8 years ago

Thanks ;)

jameswyse commented 8 years ago

Oops sorry! I just realised that today when I was looking in to the handleModels problem. Good catch on both :+1: