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

Commit

Permalink
fix(carousel): cancel goNext on scope destruction
Browse files Browse the repository at this point in the history
Discovered after #1451
  • Loading branch information
chrisirhc authored and pkozlowski-opensource committed Dec 24, 2013
1 parent 0b39994 commit 7515df4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
currentTimeout, isPlaying;
self.currentSlide = null;

var destroyed = false;
/* direction: "prev" or "next" */
self.select = function(nextSlide, direction) {
var nextIndex = slides.indexOf(nextSlide);
Expand All @@ -31,6 +32,8 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
}
}
function goNext() {
// Scope has been destroyed, stop here.
if (destroyed) { return; }
//If we have a slide to transition from and we have a transition type and we're allowed, go
if (self.currentSlide && angular.isString(direction) && !$scope.noTransition && nextSlide.$element) {
//We shouldn't do class manip in here, but it's the same weird thing bootstrap does. need to fix sometime
Expand Down Expand Up @@ -66,6 +69,9 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
$scope.$currentTransition = null;
}
};
$scope.$on('$destroy', function () {
destroyed = true;
});

/* Allow outside people to call indexOf on slides array */
self.indexOfSlide = function(slide) {
Expand Down
13 changes: 13 additions & 0 deletions src/carousel/test/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ describe('carousel', function() {
next.click();
testSlideActive(1);
});

it('issue 1414 - should not continue running timers after scope is destroyed', function() {
testSlideActive(0);
$timeout.flush();
testSlideActive(1);
$timeout.flush();
testSlideActive(2);
$timeout.flush();
testSlideActive(0);
scope.$destroy();
expect($timeout.flush).toThrow('No deferred tasks to be flushed');
});

});

describe('controller', function() {
Expand Down

0 comments on commit 7515df4

Please sign in to comment.