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

Commit

Permalink
fix(carousel): reset $currentTransition when no slides
Browse files Browse the repository at this point in the history
- Reset `$currentTransition` when there are no slides

Closes #4532
Fixes #4390
  • Loading branch information
wesleycho committed Oct 3, 2015
1 parent 3aa9841 commit 0b3d5bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ angular.module('ui.bootstrap.carousel', [])
};

$scope.$watch('interval', restartTimer);
$scope.$watchCollection('slides', resetTransition);
$scope.$on('$destroy', resetTimer);

function restartTimer() {
Expand All @@ -148,6 +149,12 @@ angular.module('ui.bootstrap.carousel', [])
}
}

function resetTransition(slides) {
if (!slides.length) {
$scope.$currentTransition = null;
}
}

$scope.play = function() {
if (!isPlaying) {
isPlaying = true;
Expand Down
21 changes: 18 additions & 3 deletions src/carousel/test/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('carousel', function() {
});

function testSlideActive(slideIndex) {
for (var i=0; i<scope.slides.length; i++) {
for (var i = 0; i < scope.slides.length; i++) {
if (i == slideIndex) {
expect(scope.slides[i].active).toBe(true);
} else {
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('carousel', function() {
});

it('should hide navigation when only one slide', function () {
scope.slides=[{active:false,content:'one'}];
scope.slides = [{active:false,content:'one'}];
scope.$apply();
elm = $compile(
'<uib-carousel interval="interval" no-transition="true">' +
Expand Down Expand Up @@ -302,7 +302,7 @@ describe('carousel', function() {
});

it('should change dom when you reassign ng-repeat slides array', function() {
scope.slides=[{content:'new1'},{content:'new2'},{content:'new3'}];
scope.slides = [{content:'new1'},{content:'new2'},{content:'new3'}];
scope.$apply();
var contents = elm.find('div.item');
expect(contents.length).toBe(3);
Expand Down Expand Up @@ -339,6 +339,21 @@ describe('carousel', function() {
expect($interval.cancel).toHaveBeenCalled();
});

it('issue 4390 - should reset the currentTransition if there are no slides', function() {
var carouselScope = elm.children().scope();
var next = elm.find('a.right');
scope.slides = [{content:'new1'},{content:'new2'},{content:'new3'}];
scope.$apply();

testSlideActive(0);
carouselScope.$currentTransition = true;

scope.slides = [];
scope.$apply();

expect(carouselScope.$currentTransition).toBe(null);
});

describe('slide order', function() {

beforeEach(function() {
Expand Down

0 comments on commit 0b3d5bd

Please sign in to comment.