Skip to content

Instantly share code, notes, and snippets.

@bohoffi
Last active December 13, 2016 09:16
Show Gist options
  • Save bohoffi/29468c38cec8f5c0a722249b702c7d4b to your computer and use it in GitHub Desktop.
Save bohoffi/29468c38cec8f5c0a722249b702c7d4b to your computer and use it in GitHub Desktop.
Angular 1 paging directive
(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