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

Commit

Permalink
fix(carousel): ensure there are slides present
Browse files Browse the repository at this point in the history
- Ensure there are slides present before calling `$scope.next` in timer

Fixes #3755
  • Loading branch information
wesleycho committed Jun 11, 2015
1 parent f02a24d commit 115d490
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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

0 comments on commit 115d490

Please sign in to comment.