user2324369
user2324369

Reputation: 321

Can't Get AngularUI Sortable Demo to work

Having trouble getting a simple sortable demo for angular-ui going here- http://jsfiddle.net/B3YDr/:

<div ng-app="myApp" ng-controller="myCtrl">
<ul ng-model="items" ui-sortable>
    <li ng-repeat="item in items">{{item}}</li>
</ul>
<pre>{{items}}</pre>
</div>


angular.module('myApp', ['ui']);
var myCtrl = function($scope) {
    $scope.items = ['One','Two','Three'];
};

I've copied the sample code almost like-for-like here http://angular-ui.github.io/#directives-sortable but still can't reorder list items.

Can anyone point out what is wrong? Thanks

Upvotes: 0

Views: 3128

Answers (2)

Narendra Dharajiya
Narendra Dharajiya

Reputation: 11

you can use methods in sortableOptions like below code

$scope.sortableOptions = {
            handle: '.custom-ctrl-handle',
            stop: function(e, ui) {
                // console.log("stop function worked");
            }
        };

Upvotes: 0

Guillaume86
Guillaume86

Reputation: 14400

You need to control the import order of scripts:

http://jsfiddle.net/B3YDr/4/

Put jquery before angular for angular to use it as element service.

<div ng-app="myApp" ng-controller="myCtrl">
    <ul ng-model="items" ui-sortable>
        <li ng-repeat="item in items">{{item}}</li>
    </ul>
    <pre>{{items}}</pre>
</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.1.3/angular.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui/0.4.0/angular-ui.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.2.0/ui-bootstrap-tpls.js"></script>

Upvotes: 5

Related Questions