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

Commit 0b3d5bd

Browse files
committed
fix(carousel): reset $currentTransition when no slides
- Reset `$currentTransition` when there are no slides Closes #4532 Fixes #4390
1 parent 3aa9841 commit 0b3d5bd

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/carousel/carousel.js

+7
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ angular.module('ui.bootstrap.carousel', [])
122122
};
123123

124124
$scope.$watch('interval', restartTimer);
125+
$scope.$watchCollection('slides', resetTransition);
125126
$scope.$on('$destroy', resetTimer);
126127

127128
function restartTimer() {
@@ -148,6 +149,12 @@ angular.module('ui.bootstrap.carousel', [])
148149
}
149150
}
150151

152+
function resetTransition(slides) {
153+
if (!slides.length) {
154+
$scope.$currentTransition = null;
155+
}
156+
}
157+
151158
$scope.play = function() {
152159
if (!isPlaying) {
153160
isPlaying = true;

src/carousel/test/carousel.spec.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('carousel', function() {
4545
});
4646

4747
function testSlideActive(slideIndex) {
48-
for (var i=0; i<scope.slides.length; i++) {
48+
for (var i = 0; i < scope.slides.length; i++) {
4949
if (i == slideIndex) {
5050
expect(scope.slides[i].active).toBe(true);
5151
} else {
@@ -143,7 +143,7 @@ describe('carousel', function() {
143143
});
144144

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

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

342+
it('issue 4390 - should reset the currentTransition if there are no slides', function() {
343+
var carouselScope = elm.children().scope();
344+
var next = elm.find('a.right');
345+
scope.slides = [{content:'new1'},{content:'new2'},{content:'new3'}];
346+
scope.$apply();
347+
348+
testSlideActive(0);
349+
carouselScope.$currentTransition = true;
350+
351+
scope.slides = [];
352+
scope.$apply();
353+
354+
expect(carouselScope.$currentTransition).toBe(null);
355+
});
356+
342357
describe('slide order', function() {
343358

344359
beforeEach(function() {

0 commit comments

Comments
 (0)