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

fix(carousel): reset $currentTransition when no slides #4532

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
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