Created
November 14, 2016 16:56
-
-
Save Zerg00s/0154544bcaca118d70149ceaa60f860c to your computer and use it in GitHub Desktop.
Move element inside Angular ng-repeat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.directive('ngVisible', function () { | |
return function (scope, element, attr) { | |
scope.$watch(attr.ngVisible, function (visible) { | |
element.css('visibility', visible ? 'visible' : 'hidden'); | |
}); | |
}; | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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