diff --git a/src/carousel/carousel.js b/src/carousel/carousel.js index ce50c9429a..8fc66e5ef8 100644 --- a/src/carousel/carousel.js +++ b/src/carousel/carousel.js @@ -113,7 +113,7 @@ angular.module('ui.bootstrap.carousel', []) function timerFn() { var interval = +$scope.interval; - if (isPlaying && !isNaN(interval) && interval > 0) { + if (isPlaying && !isNaN(interval) && interval > 0 && slides.length) { $scope.next(); } else { $scope.pause(); diff --git a/src/carousel/test/carousel.spec.js b/src/carousel/test/carousel.spec.js index 86e5a0735a..82a878d659 100644 --- a/src/carousel/test/carousel.spec.js +++ b/src/carousel/test/carousel.spec.js @@ -146,7 +146,7 @@ describe('carousel', function() { testSlideActive(1); }); - it('shouldnt go forward if interval is NaN or negative', function() { + it('shouldnt go forward if interval is NaN or negative or has no slides', function() { testSlideActive(0); var previousInterval = scope.interval; scope.$apply('interval = -1'); @@ -161,6 +161,9 @@ describe('carousel', function() { scope.$apply('interval = 1000'); $interval.flush(1000); testSlideActive(2); + scope.$apply('slides = []'); + $interval.flush(1000); + testSlideActive(2); }); it('should bind the content to slides', function() {