Skip to content

Instantly share code, notes, and snippets.

//Angularjs 1.1 looping though an array, for use with next and previous buttons.
//Two different styles that do the same thing
//This loops through an array
$scope.nextItem = (Number($routeParams.itemId) + 1) % $scope.artists.length;
$scope.prevItem = (Number($routeParams.itemId) + $scope.artists.length - 1) % $scope.artists.length;
//This is the same thing as above
if ($routeParams.itemId > 0) {
$scope.prevItem = Number($routeParams.itemId) - 1;