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

feat(timepicker): set templateUrl from uibTimepickerConfig #5200

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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