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

Commit

Permalink
feat(timepicker): add templateUrl in timepickerConfig
Browse files Browse the repository at this point in the history
- Sets the default templateUrl in `uibTimepickerConfig`

Closes #5087
Closes #5200
  • Loading branch information
deeg authored and wesleycho committed Jan 11, 2016
1 parent aa010b0 commit 4b0e381
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/timepicker/test/timepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,28 @@ describe('timepicker directive', function() {
});
});

describe('setting uibTimepickerConfig tmeplate url', function() {
var originalConfig = {};
var newTemplateUrl = 'foo/bar.html';
beforeEach(inject(function(_$compile_, _$rootScope_, uibTimepickerConfig) {
angular.extend(originalConfig, uibTimepickerConfig);
$templateCache.put(newTemplateUrl, '<div>baz</div>');
uibTimepickerConfig.templateUrl = newTemplateUrl;

element = $compile('<uib-timepicker ng-model="time"></uib-timepicker>')($rootScope);
$rootScope.$digest();
}));
afterEach(inject(function(uibTimepickerConfig) {
// return it to the original state
angular.extend(uibTimepickerConfig, originalConfig);
}));

it('should use a custom template', function() {
expect(element[0].tagName.toLowerCase()).toBe('div');
expect(element.html()).toBe('baz');
});
});

describe('$formatter', function() {
var ngModel,
date;
Expand Down
7 changes: 4 additions & 3 deletions src/timepicker/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ angular.module('ui.bootstrap.timepicker', [])
readonlyInput: false,
mousewheel: true,
arrowkeys: true,
showSpinners: true
showSpinners: true,
templateUrl: 'uib/template/timepicker/timepicker.html'
})

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

.directive('uibTimepicker', function() {
.directive('uibTimepicker', function(uibTimepickerConfig) {
return {
require: ['uibTimepicker', '?^ngModel'],
controller: 'UibTimepickerController',
controllerAs: 'timepicker',
replace: true,
scope: {},
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'uib/template/timepicker/timepicker.html';
return attrs.templateUrl || uibTimepickerConfig.templateUrl;
},
link: function(scope, element, attrs, ctrls) {
var timepickerCtrl = ctrls[0], ngModelCtrl = ctrls[1];
Expand Down

0 comments on commit 4b0e381

Please sign in to comment.