diff --git a/src/carousel/carousel.js b/src/carousel/carousel.js index 86aae0f4d4..733c1caa61 100644 --- a/src/carousel/carousel.js +++ b/src/carousel/carousel.js @@ -251,7 +251,9 @@ angular.module('ui.bootstrap.carousel', []) controller: 'CarouselController', controllerAs: 'carousel', require: 'carousel', - templateUrl: 'template/carousel/carousel.html', + templateUrl: function(element, attrs) { + return attrs.templateUrl || 'template/carousel/carousel.html'; + }, scope: { interval: '=', noTransition: '=', @@ -309,7 +311,9 @@ function CarouselDemoCtrl($scope) { restrict: 'EA', transclude: true, replace: true, - templateUrl: 'template/carousel/slide.html', + templateUrl: function(element, attrs) { + return attrs.templateUrl || 'template/carousel/slide.html'; + }, scope: { active: '=?', index: '=?' diff --git a/src/carousel/docs/README.md b/src/carousel/docs/README.md index 295378e0c4..bf8bbe2225 100644 --- a/src/carousel/docs/README.md +++ b/src/carousel/docs/README.md @@ -4,4 +4,6 @@ The carousel also offers support for touchscreen devices in the form of swiping. Use a `` element with `` 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. -Use the no-wrap attribute on a `` element to control the looping of slides; setting no-wrap to an expression which evaluates to a truthy value will prevent looping +Use the `no-wrap` attribute on a `` element to control the looping of slides; setting `no-wrap` to an expression which evaluates to a truthy value will prevent looping + +Use the `template-url` attribute on a `` or `` element to specify the url of a custom template to override the default templates diff --git a/src/carousel/test/carousel.spec.js b/src/carousel/test/carousel.spec.js index 1e4be5cfee..e1db5a5155 100644 --- a/src/carousel/test/carousel.spec.js +++ b/src/carousel/test/carousel.spec.js @@ -14,12 +14,13 @@ describe('carousel', function() { })); beforeEach(module('template/carousel/carousel.html', 'template/carousel/slide.html')); - var $rootScope, $compile, $controller, $interval; - beforeEach(inject(function(_$rootScope_, _$compile_, _$controller_, _$interval_) { + var $rootScope, $compile, $controller, $interval, $templateCache; + beforeEach(inject(function(_$rootScope_, _$compile_, _$controller_, _$interval_, _$templateCache_) { $rootScope = _$rootScope_; $compile = _$compile_; $controller = _$controller_; $interval = _$interval_; + $templateCache = _$templateCache_; })); describe('basics', function() { @@ -53,6 +54,29 @@ describe('carousel', function() { } } + it('should allow overriding of the carousel template', function() { + $templateCache.put('foo/bar.html', '
foo
'); + + elm = $compile('')(scope); + $rootScope.$digest(); + + expect(elm.html()).toBe('foo'); + }); + + it('should allow overriding of the slide template', function() { + $templateCache.put('foo/bar.html', '
bar
'); + + elm = $compile( + '' + + '' + + '' + )(scope); + $rootScope.$digest(); + + var slide = elm.find('.slide'); + expect(slide.html()).toBe('bar'); + }); + it('should set the selected slide to active = true', function() { expect(scope.slides[0].content).toBe('one'); testSlideActive(0);