Skip to content

Instantly share code, notes, and snippets.

@Zerg00s
Created November 14, 2016 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zerg00s/0154544bcaca118d70149ceaa60f860c to your computer and use it in GitHub Desktop.
Save Zerg00s/0154544bcaca118d70149ceaa60f860c to your computer and use it in GitHub Desktop.
Move element inside Angular ng-repeat
// Move list items up or down or swap
$scope.moveItem = function (array, origin, destination) {
var temp = array[destination];
array[destination] = array[origin];
array[origin] = temp;
};
// Move list item Up
$scope.listItemUp = function (itemIndex, array) {
$scope.moveItem(array, itemIndex, itemIndex - 1);
};
// Move list item Down
$scope.listItemDown = function (itemIndex, array) {
$scope.moveItem(array, itemIndex, itemIndex + 1);
};
app.directive('ngVisible', function () {
return function (scope, element, attr) {
scope.$watch(attr.ngVisible, function (visible) {
element.css('visibility', visible ? 'visible' : 'hidden');
});
};
})
<button type="button" class="btn-info pull-right subLinkMove" ng-click="listItemUp($index, tab.Sublinks)" ng-visible="$first == false">
<i class="fa fa-arrow-up "></i>
</button>
<button type="button" class="btn-info pull-right subLinkMove" ng-click="listItemDown($index, tab.Sublinks)" ng-visible="$last == false">
<i class="fa fa-arrow-down "></i>
</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment