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

Commit 4b0e381

Browse files
deegwesleycho
authored andcommitted
feat(timepicker): add templateUrl in timepickerConfig
- Sets the default templateUrl in `uibTimepickerConfig` Closes #5087 Closes #5200
1 parent aa010b0 commit 4b0e381

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/timepicker/test/timepicker.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,28 @@ describe('timepicker directive', function() {
10771077
});
10781078
});
10791079

1080+
describe('setting uibTimepickerConfig tmeplate url', function() {
1081+
var originalConfig = {};
1082+
var newTemplateUrl = 'foo/bar.html';
1083+
beforeEach(inject(function(_$compile_, _$rootScope_, uibTimepickerConfig) {
1084+
angular.extend(originalConfig, uibTimepickerConfig);
1085+
$templateCache.put(newTemplateUrl, '<div>baz</div>');
1086+
uibTimepickerConfig.templateUrl = newTemplateUrl;
1087+
1088+
element = $compile('<uib-timepicker ng-model="time"></uib-timepicker>')($rootScope);
1089+
$rootScope.$digest();
1090+
}));
1091+
afterEach(inject(function(uibTimepickerConfig) {
1092+
// return it to the original state
1093+
angular.extend(uibTimepickerConfig, originalConfig);
1094+
}));
1095+
1096+
it('should use a custom template', function() {
1097+
expect(element[0].tagName.toLowerCase()).toBe('div');
1098+
expect(element.html()).toBe('baz');
1099+
});
1100+
});
1101+
10801102
describe('$formatter', function() {
10811103
var ngModel,
10821104
date;

src/timepicker/timepicker.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ angular.module('ui.bootstrap.timepicker', [])
1010
readonlyInput: false,
1111
mousewheel: true,
1212
arrowkeys: true,
13-
showSpinners: true
13+
showSpinners: true,
14+
templateUrl: 'uib/template/timepicker/timepicker.html'
1415
})
1516

1617
.controller('UibTimepickerController', ['$scope', '$element', '$attrs', '$parse', '$log', '$locale', 'uibTimepickerConfig', function($scope, $element, $attrs, $parse, $log, $locale, timepickerConfig) {
@@ -519,15 +520,15 @@ angular.module('ui.bootstrap.timepicker', [])
519520
};
520521
}])
521522

522-
.directive('uibTimepicker', function() {
523+
.directive('uibTimepicker', function(uibTimepickerConfig) {
523524
return {
524525
require: ['uibTimepicker', '?^ngModel'],
525526
controller: 'UibTimepickerController',
526527
controllerAs: 'timepicker',
527528
replace: true,
528529
scope: {},
529530
templateUrl: function(element, attrs) {
530-
return attrs.templateUrl || 'uib/template/timepicker/timepicker.html';
531+
return attrs.templateUrl || uibTimepickerConfig.templateUrl;
531532
},
532533
link: function(scope, element, attrs, ctrls) {
533534
var timepickerCtrl = ctrls[0], ngModelCtrl = ctrls[1];

0 commit comments

Comments
 (0)