Skip to content

Instantly share code, notes, and snippets.

@Florian95
Last active August 29, 2015 14:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Florian95/725d6d3aae57fc6b8bee to your computer and use it in GitHub Desktop.
Save Florian95/725d6d3aae57fc6b8bee to your computer and use it in GitHub Desktop.
ngSortable by Florian95
<div ng-app='ngSortable'>
<ul id="items" ng-sortable ng-model="items">
<span ng-bind='item'></span>
</ul>
<hr/>
<span ng-bind='items | json'></span>
</div>
app = angular.module('ngSortable', [])
app.run ($rootScope) ->
$rootScope.items = ['Bob', 'Pierre', 'Marie']
app.directive 'ngSortable', ->
restrict: 'AE'
transclude: true
scope:
model: '=ngModel'
template: "<li ng-repeat='(i, item) in model' index='{{i}}' ng-transclude></li>"
link: (scope, element, attrs) ->
new Sortable(element[0],
onUpdate: (evt) ->
a = []
for item, i in element.find('li')
a[i] = angular.element(item).scope().item
scope.model = a
scope.$apply()
return
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment