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

Commit a0e1c91

Browse files
committed
feat(pagination): add templateUrl support
- Add support for overriding the template url on an instance by instance basis - Expose the controller to the view via `controllerAs` Closes #4137
1 parent 5a28ff7 commit a0e1c91

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/pagination/docs/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ Settings can be provided as attributes in the `<pagination>` or globally configu
6161
_(Default: 'Last')_ :
6262
Text for Last button.
6363

64+
* `template-url`
65+
_(Default: 'template/pagination/pagination.html') :
66+
Override the template for the component with a custom provided template
67+
6468
### Pager Settings ###
6569

6670
Settings can be provided as attributes in the `<pager>` or globally configured through the `pagerConfig`.

src/pagination/pagination.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ angular.module('ui.bootstrap.pagination', [])
9595
},
9696
require: ['pagination', '?ngModel'],
9797
controller: 'PaginationController',
98-
templateUrl: 'template/pagination/pagination.html',
98+
controllerAs: 'pagination',
99+
templateUrl: function(element, attrs) {
100+
return attrs.templateUrl || 'template/pagination/pagination.html';
101+
},
99102
replace: true,
100103
link: function(scope, element, attrs, ctrls) {
101104
var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];

src/pagination/test/pagination.spec.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
describe('pagination directive', function () {
2-
var $compile, $rootScope, $document, element;
2+
var $compile, $rootScope, $document, $templateCache, element;
33
beforeEach(module('ui.bootstrap.pagination'));
44
beforeEach(module('template/pagination/pagination.html'));
5-
beforeEach(inject(function(_$compile_, _$rootScope_, _$document_) {
5+
beforeEach(inject(function(_$compile_, _$rootScope_, _$document_, _$templateCache_) {
66
$compile = _$compile_;
77
$rootScope = _$rootScope_;
88
$rootScope.total = 47; // 5 pages
99
$rootScope.currentPage = 3;
1010
$rootScope.disabled = false;
1111
$document = _$document_;
12+
$templateCache = _$templateCache_;
1213
element = $compile('<pagination total-items="total" ng-model="currentPage"></pagination>')($rootScope);
1314
$rootScope.$digest();
1415
}));
@@ -44,6 +45,33 @@ describe('pagination directive', function () {
4445
expect(element.hasClass('pagination')).toBe(true);
4546
});
4647

48+
it('exposes the controller to the template', function() {
49+
$templateCache.put('template/pagination/pagination.html', '<div>{{pagination.randomText}}</div>');
50+
var scope = $rootScope.$new();
51+
52+
element = $compile('<pagination></pagination>')(scope);
53+
$rootScope.$digest();
54+
55+
var ctrl = element.controller('pagination');
56+
57+
expect(ctrl).toBeDefined();
58+
59+
ctrl.randomText = 'foo';
60+
$rootScope.$digest();
61+
62+
expect(element.html()).toBe('foo');
63+
});
64+
65+
it('allows custom templates', function() {
66+
$templateCache.put('foo/bar.html', '<div>baz</div>');
67+
var scope = $rootScope.$new();
68+
69+
element = $compile('<pagination template-url="foo/bar.html"></pagination>')(scope);
70+
$rootScope.$digest();
71+
72+
expect(element.html()).toBe('baz');
73+
});
74+
4775
it('contains num-pages + 2 li elements', function() {
4876
expect(getPaginationBarSize()).toBe(7);
4977
expect(getPaginationEl(0).text()).toBe('Previous');

0 commit comments

Comments
 (0)