import {module} from '../module'; import './style.scss'; export default class Paging { get numPages() { return Math.ceil(this.numItems / this.numPerPage); } constructor($http, $scope) { this.$http = $http; this.$scope = $scope; this.where = this.filter; this.numPerPage = null; this.numItems = 0; $scope.$watch('$ctrl.index.model.length', () => this.onModelUpdated()); } $onChanges(changes) { if (!this.index) return; this.numPerPage = this.index.filter.size; if(changes.total) this.numItems = changes.total.currentValue; } onModelUpdated() { let index = this.index; let filter = index.filter; if (filter.page >= this.numPages && index.model.length >= this.numPerPage) this.numItems = filter.page * filter.size + 1; } onPageChange(page) { this.index.filter.page = page; this.index.accept(); } } Paging.$inject = ['$http', '$scope']; export const NAME = 'vnPaging'; export const COMPONENT = { template: require('./paging.html'), bindings: { index: '<', total: '<' }, controller: Paging }; module.component(NAME, COMPONENT);