diff --git a/src/carousel/carousel.js b/src/carousel/carousel.js index c721e07055..0ba813dc01 100644 --- a/src/carousel/carousel.js +++ b/src/carousel/carousel.js @@ -122,6 +122,7 @@ angular.module('ui.bootstrap.carousel', []) }; $scope.$watch('interval', restartTimer); + $scope.$watchCollection('slides', resetTransition); $scope.$on('$destroy', resetTimer); function restartTimer() { @@ -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; diff --git a/src/carousel/test/carousel.spec.js b/src/carousel/test/carousel.spec.js index 3a42ff24b5..37a6017eea 100644 --- a/src/carousel/test/carousel.spec.js +++ b/src/carousel/test/carousel.spec.js @@ -45,7 +45,7 @@ describe('carousel', function() { }); function testSlideActive(slideIndex) { - for (var i=0; i' + @@ -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); @@ -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() {