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

Commit a29c8f2

Browse files
committed
feat(carousel): add templateUrl support
- Add support for `templateUrl` attribute for `carousel` and `slide` directives for instance by instance overriding of default templates Closes #4141
1 parent 02872dc commit a29c8f2

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/carousel/carousel.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ angular.module('ui.bootstrap.carousel', [])
251251
controller: 'CarouselController',
252252
controllerAs: 'carousel',
253253
require: 'carousel',
254-
templateUrl: 'template/carousel/carousel.html',
254+
templateUrl: function(element, attrs) {
255+
return attrs.templateUrl || 'template/carousel/carousel.html';
256+
},
255257
scope: {
256258
interval: '=',
257259
noTransition: '=',
@@ -309,7 +311,9 @@ function CarouselDemoCtrl($scope) {
309311
restrict: 'EA',
310312
transclude: true,
311313
replace: true,
312-
templateUrl: 'template/carousel/slide.html',
314+
templateUrl: function(element, attrs) {
315+
return attrs.templateUrl || 'template/carousel/slide.html';
316+
},
313317
scope: {
314318
active: '=?',
315319
index: '=?'

src/carousel/docs/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ The carousel also offers support for touchscreen devices in the form of swiping.
44

55
Use a `<carousel>` element with `<slide>` elements inside it. It will automatically cycle through the slides at a given rate, and a current-index variable will be kept in sync with the currently visible slide.
66

7-
Use the no-wrap attribute on a `<carousel>` element to control the looping of slides; setting no-wrap to an expression which evaluates to a truthy value will prevent looping
7+
Use the `no-wrap` attribute on a `<carousel>` element to control the looping of slides; setting `no-wrap` to an expression which evaluates to a truthy value will prevent looping
8+
9+
Use the `template-url` attribute on a `<carousel>` or `<slide>` element to specify the url of a custom template to override the default templates

src/carousel/test/carousel.spec.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ describe('carousel', function() {
1414
}));
1515
beforeEach(module('template/carousel/carousel.html', 'template/carousel/slide.html'));
1616

17-
var $rootScope, $compile, $controller, $interval;
18-
beforeEach(inject(function(_$rootScope_, _$compile_, _$controller_, _$interval_) {
17+
var $rootScope, $compile, $controller, $interval, $templateCache;
18+
beforeEach(inject(function(_$rootScope_, _$compile_, _$controller_, _$interval_, _$templateCache_) {
1919
$rootScope = _$rootScope_;
2020
$compile = _$compile_;
2121
$controller = _$controller_;
2222
$interval = _$interval_;
23+
$templateCache = _$templateCache_;
2324
}));
2425

2526
describe('basics', function() {
@@ -53,6 +54,29 @@ describe('carousel', function() {
5354
}
5455
}
5556

57+
it('should allow overriding of the carousel template', function() {
58+
$templateCache.put('foo/bar.html', '<div>foo</div>');
59+
60+
elm = $compile('<carousel template-url="foo/bar.html"></carousel>')(scope);
61+
$rootScope.$digest();
62+
63+
expect(elm.html()).toBe('foo');
64+
});
65+
66+
it('should allow overriding of the slide template', function() {
67+
$templateCache.put('foo/bar.html', '<div class="slide">bar</div>');
68+
69+
elm = $compile(
70+
'<carousel interval="interval" no-transition="true" no-pause="nopause">' +
71+
'<slide template-url="foo/bar.html"></slide>' +
72+
'</carousel>'
73+
)(scope);
74+
$rootScope.$digest();
75+
76+
var slide = elm.find('.slide');
77+
expect(slide.html()).toBe('bar');
78+
});
79+
5680
it('should set the selected slide to active = true', function() {
5781
expect(scope.slides[0].content).toBe('one');
5882
testSlideActive(0);

0 commit comments

Comments
 (0)