Last active
December 13, 2016 09:16
-
-
Save bohoffi/29468c38cec8f5c0a722249b702c7d4b to your computer and use it in GitHub Desktop.
Angular 1 paging directive
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
(function () { | |
'use strict'; | |
angular.module('app.directives', []) | |
.directive('paging', PagingDirective); | |
function PagingDirective() { | |
return { | |
restrict: 'EA', | |
templateUrl: 'paging.tpl.html', | |
controller: ['$scope', '$element', '$stateParams', function ($scope, $element, $stateParams) { | |
var currentPage = ( !$stateParams.page ) ? 1 : parseInt($stateParams.page); | |
var linkPrefix = 'news/page/'; | |
$scope.paging = { | |
prevLink: linkPrefix + ( currentPage - 1 ), | |
nextLink: linkPrefix + ( currentPage + 1 ), | |
sep: ( !$element.attr('sep') ) ? '|' : $element.attr('sep'), | |
prevLabel: ( !$element.attr('prev-label') ) ? 'Previous page' : $element.attr('prev-label'), | |
nextLabel: ( !$element.attr('next-label') ) ? 'Next page' : $element.attr('next-label') | |
}; | |
}] | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment