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

Commit bd17b33

Browse files
committed
feat(datepicker): allow for custom templates for day / month / year
Custom templates can be specified with template-url attribute
1 parent e21866b commit bd17b33

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

Diff for: src/datepicker/datepicker.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
247247
return {
248248
restrict: 'EA',
249249
replace: true,
250-
templateUrl: attrs.templateUrl || 'template/datepicker/day.html',
250+
templateUrl: function(element, attrs) {
251+
return attrs.templateUrl || 'template/datepicker/day.html';
252+
},
251253
require: '^datepicker',
252254
link: function(scope, element, attrs, ctrl) {
253255
scope.showWeeks = ctrl.showWeeks;
@@ -359,7 +361,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
359361
return {
360362
restrict: 'EA',
361363
replace: true,
362-
templateUrl: attrs.templateUrl || 'template/datepicker/month.html',
364+
templateUrl: function(element, attrs) {
365+
return attrs.templateUrl || 'template/datepicker/month.html';
366+
},
363367
require: '^datepicker',
364368
link: function(scope, element, attrs, ctrl) {
365369
ctrl.step = { years: 1 };
@@ -417,7 +421,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
417421
return {
418422
restrict: 'EA',
419423
replace: true,
420-
templateUrl: attrs.templateUrl || 'template/datepicker/year.html',
424+
templateUrl: function(element, attrs) {
425+
return attrs.templateUrl || 'template/datepicker/year.html';
426+
},
421427
require: '^datepicker',
422428
link: function(scope, element, attrs, ctrl) {
423429
var range = ctrl.yearRange;

Diff for: 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+
'<daypicker template-url="foo/day.html"></daypicker>' +
372+
'<monthpicker template-url="foo/month.html"></monthpicker>' +
373+
'<yearpicker template-url="foo/year.html"></yearpicker>' +
374+
'</div>');
375+
376+
element = $compile('<datepicker ng-model="date" template-url="foo/bar.html"></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)