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

Commit 1f65d87

Browse files
filsowesleycho
authored andcommitted
feat(datepicker): add templateUrl support for pickers
- Add support for custom template urls for `uibDaypicker`, `uibMonthpicker`, and `uibYearpicker` Closes #4432
1 parent 16dafd5 commit 1f65d87

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/datepicker/datepicker.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
458458
.directive('uibDaypicker', function() {
459459
return {
460460
replace: true,
461-
templateUrl: 'template/datepicker/day.html',
461+
templateUrl: function(element, attrs) {
462+
return attrs.templateUrl || 'template/datepicker/day.html';
463+
},
462464
require: ['^?uibDatepicker', 'uibDaypicker', '^?datepicker'],
463465
controller: 'UibDaypickerController',
464466
link: function(scope, element, attrs, ctrls) {
@@ -473,7 +475,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
473475
.directive('uibMonthpicker', function() {
474476
return {
475477
replace: true,
476-
templateUrl: 'template/datepicker/month.html',
478+
templateUrl: function(element, attrs) {
479+
return attrs.templateUrl || 'template/datepicker/month.html';
480+
},
477481
require: ['^?uibDatepicker', 'uibMonthpicker', '^?datepicker'],
478482
controller: 'UibMonthpickerController',
479483
link: function(scope, element, attrs, ctrls) {
@@ -488,7 +492,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
488492
.directive('uibYearpicker', function() {
489493
return {
490494
replace: true,
491-
templateUrl: 'template/datepicker/year.html',
495+
templateUrl: function(element, attrs) {
496+
return attrs.templateUrl || 'template/datepicker/year.html';
497+
},
492498
require: ['^?uibDatepicker', 'uibYearpicker', '^?datepicker'],
493499
controller: 'UibYearpickerController',
494500
link: function(scope, element, attrs, ctrls) {
@@ -1034,7 +1040,7 @@ angular.module('ui.bootstrap.datepicker')
10341040
var focusElement = function() {
10351041
self.element[0].focus();
10361042
};
1037-
1043+
10381044
$scope.$on('uib:datepicker.focus', focusElement);
10391045

10401046
$scope.keydown = function(evt) {

src/datepicker/test/datepicker.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,25 @@ describe('datepicker directive', function() {
362362
expect(element.html()).toBe('baz');
363363
});
364364

365+
it('should support custom day, month and year templates', function() {
366+
$templateCache.put('foo/day.html', '<div>day</div>');
367+
$templateCache.put('foo/month.html', '<div>month</div>');
368+
$templateCache.put('foo/year.html', '<div>year</div>');
369+
370+
$templateCache.put('foo/bar.html', '<div>' +
371+
'<uib-daypicker template-url="foo/day.html"></uib-daypicker>' +
372+
'<uib-monthpicker template-url="foo/month.html"></uib-monthpicker>' +
373+
'<uib-yearpicker template-url="foo/year.html"></uib-yearpicker>' +
374+
'</div>');
375+
376+
element = $compile('<uib-datepicker ng-model="date" template-url="foo/bar.html"></uib-datepicker>')($rootScope);
377+
$rootScope.$digest();
378+
379+
var expectedHtml = '<div template-url="foo/day.html">day</div><div template-url="foo/month.html">month</div><div template-url="foo/year.html">year</div>';
380+
381+
expect(element.html()).toBe(expectedHtml);
382+
});
383+
365384
it('should expose the controller in the template', function() {
366385
$templateCache.put('template/datepicker/datepicker.html', '<div>{{datepicker.text}}</div>');
367386

0 commit comments

Comments
 (0)