Add Sortable function, based on https://github.com/RubaXa/Sortable
A Pen by Florian LAMACHE on CodePen.
Add Sortable function, based on https://github.com/RubaXa/Sortable
A Pen by Florian LAMACHE on CodePen.
| <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 | |
| ) |