Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.