Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

feat(pagination): add templateUrl support #4137

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/pagination/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Settings can be provided as attributes in the `<pagination>` or globally configu
_(Default: 'Last')_ :
Text for Last button.

* `template-url`
_(Default: 'template/pagination/pagination.html') :
Override the template for the component with a custom provided template

### Pager Settings ###

Settings can be provided as attributes in the `<pager>` or globally configured through the `pagerConfig`.
Expand Down
5 changes: 4 additions & 1 deletion src/pagination/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ angular.module('ui.bootstrap.pagination', [])
},
require: ['pagination', '?ngModel'],
controller: 'PaginationController',
templateUrl: 'template/pagination/pagination.html',
controllerAs: 'pagination',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/pagination/pagination.html';
},
replace: true,
link: function(scope, element, attrs, ctrls) {
var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];
Expand Down
32 changes: 30 additions & 2 deletions src/pagination/test/pagination.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
describe('pagination directive', function () {
var $compile, $rootScope, $document, element;
var $compile, $rootScope, $document, $templateCache, element;
beforeEach(module('ui.bootstrap.pagination'));
beforeEach(module('template/pagination/pagination.html'));
beforeEach(inject(function(_$compile_, _$rootScope_, _$document_) {
beforeEach(inject(function(_$compile_, _$rootScope_, _$document_, _$templateCache_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$rootScope.total = 47; // 5 pages
$rootScope.currentPage = 3;
$rootScope.disabled = false;
$document = _$document_;
$templateCache = _$templateCache_;
element = $compile('<pagination total-items="total" ng-model="currentPage"></pagination>')($rootScope);
$rootScope.$digest();
}));
Expand Down Expand Up @@ -44,6 +45,33 @@ describe('pagination directive', function () {
expect(element.hasClass('pagination')).toBe(true);
});

it('exposes the controller to the template', function() {
$templateCache.put('template/pagination/pagination.html', '<div>{{pagination.randomText}}</div>');
var scope = $rootScope.$new();

element = $compile('<pagination></pagination>')(scope);
$rootScope.$digest();

var ctrl = element.controller('pagination');

expect(ctrl).toBeDefined();

ctrl.randomText = 'foo';
$rootScope.$digest();

expect(element.html()).toBe('foo');
});

it('allows custom templates', function() {
$templateCache.put('foo/bar.html', '<div>baz</div>');
var scope = $rootScope.$new();

element = $compile('<pagination template-url="foo/bar.html"></pagination>')(scope);
$rootScope.$digest();

expect(element.html()).toBe('baz');
});

it('contains num-pages + 2 li elements', function() {
expect(getPaginationBarSize()).toBe(7);
expect(getPaginationEl(0).text()).toBe('Previous');
Expand Down