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

Commit 115d490

Browse files
committed
fix(carousel): ensure there are slides present
- Ensure there are slides present before calling `$scope.next` in timer Fixes #3755
1 parent f02a24d commit 115d490

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/carousel/carousel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ angular.module('ui.bootstrap.carousel', [])
113113

114114
function timerFn() {
115115
var interval = +$scope.interval;
116-
if (isPlaying && !isNaN(interval) && interval > 0) {
116+
if (isPlaying && !isNaN(interval) && interval > 0 && slides.length) {
117117
$scope.next();
118118
} else {
119119
$scope.pause();

src/carousel/test/carousel.spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ describe('carousel', function() {
146146
testSlideActive(1);
147147
});
148148

149-
it('shouldnt go forward if interval is NaN or negative', function() {
149+
it('shouldnt go forward if interval is NaN or negative or has no slides', function() {
150150
testSlideActive(0);
151151
var previousInterval = scope.interval;
152152
scope.$apply('interval = -1');
@@ -161,6 +161,9 @@ describe('carousel', function() {
161161
scope.$apply('interval = 1000');
162162
$interval.flush(1000);
163163
testSlideActive(2);
164+
scope.$apply('slides = []');
165+
$interval.flush(1000);
166+
testSlideActive(2);
164167
});
165168

166169
it('should bind the content to slides', function() {

0 commit comments

Comments
 (0)