a5hik / ng-sortable

AngularJS Library for Drag and Drop, supports Sortable and Draggable. Supports Touch devices.
http://a5hik.github.io/ng-sortable/
MIT License
1.15k stars 314 forks source link

scope.itemScope.element.prop is not a function #251

Open loverdrive opened 8 years ago

loverdrive commented 8 years ago

Hi, i'm implementing ng-sortable. This is my html:

<div as-sortable="dragOptions" ng-model="startDrag">
    <div id="{{startDrag[$index].id}}" class="draggable" ng-repeat="element in startDrag" data-as-sortable-item>
        <p data-as-sortable-item-handle>
            {{startDrag[$index].name}}
        </p>
    </div>
</div>

When i move the first element, it is sorted correctly. But when i move the second element (included the same previous element), it give me the error:

Uncaught TypeError: scope.itemScope.element.prop is not a function    [ng-sortable.js:718]

Have you any idea what could be the problem? Thank you!

Zemke commented 7 years ago

Hey fellow in misery, I’d just fumbled around with this as well and it turned out you mustn’t use element as the reference to an entry in your array. So, maybe use something like ng-repeat="elem in startDrag" instead.

saurabhj commented 3 years ago

Thanks, @Zemke! We have this plugin implemented at multiple places in our project and it all works fine -- but this one new place I was trying to add it and it was behaving weirdly and throwing this issue.

Your comment saved me from going crazy 😊 Turned out, I was referring to our element as element 🤷