-
Notifications
You must be signed in to change notification settings - Fork 1
/
page-size-changer.js
32 lines (31 loc) · 1.07 KB
/
page-size-changer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
angular.module('seblucas.slPageSizeChanger', [])
.directive('slPageSizeChanger', function() {
return {
restrict: 'E',
require: '^ngModel',
scope: {
itemsPerPageList: '=',
totalItems: '=',
},
template:
'<ul class="pagination pull-right"> \
<li ng-repeat="itemValue in itemsPerPageList" ng-class="{active: itemsPerPage == itemValue}"><a href="" ng-click="selectItemPerPage(itemValue)">{{itemValue}}</a></li> \
<li ng-if="totalItems" class="disabled"><a href="">Total : {{totalItems}}</a></li> \
</ul>',
link: function(scope, element, attrs, ngModel) {
ngModel.$viewChangeListeners.push(function() {
scope.$eval(attrs.ngChange);
});
ngModel.$render = function() {
scope.itemsPerPage = ngModel.$modelValue;
};
scope.selectItemPerPage = function(value) {
if (scope.itemsPerPage !== value) {
scope.itemsPerPage = value;
ngModel.$setViewValue(value);
}
};
}
};
});