diff --git a/src/pagination/docs/readme.md b/src/pagination/docs/readme.md index 66733bff16..0b55b66695 100644 --- a/src/pagination/docs/readme.md +++ b/src/pagination/docs/readme.md @@ -61,6 +61,10 @@ Settings can be provided as attributes in the `` 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 `` or globally configured through the `pagerConfig`. diff --git a/src/pagination/pagination.js b/src/pagination/pagination.js index 503345a009..64086b7ab0 100644 --- a/src/pagination/pagination.js +++ b/src/pagination/pagination.js @@ -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]; diff --git a/src/pagination/test/pagination.spec.js b/src/pagination/test/pagination.spec.js index 968df358bf..54881b4f69 100644 --- a/src/pagination/test/pagination.spec.js +++ b/src/pagination/test/pagination.spec.js @@ -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('')($rootScope); $rootScope.$digest(); })); @@ -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', '
{{pagination.randomText}}
'); + var scope = $rootScope.$new(); + + element = $compile('')(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', '
baz
'); + var scope = $rootScope.$new(); + + element = $compile('')(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');