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

fix(carousel): ensure there are slides present #3788

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion src/carousel/test/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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() {
Expand Down