From 115d490a251a557828ecc24e12367abc5ef009c5 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Tue, 9 Jun 2015 23:23:11 -0700 Subject: [PATCH] fix(carousel): ensure there are slides present - Ensure there are slides present before calling `$scope.next` in timer Fixes #3755 --- src/carousel/carousel.js | 2 +- src/carousel/test/carousel.spec.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) 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() {