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

[Carousel] TypeError: Cannot read property 'index' of undefined #3755

Closed
sylvainbx opened this issue Jun 4, 2015 · 4 comments
Closed

[Carousel] TypeError: Cannot read property 'index' of undefined #3755

sylvainbx opened this issue Jun 4, 2015 · 4 comments

Comments

@sylvainbx
Copy link

In carousel.js#L76, if slides.length == 0, newIndex will be NaN.
This will cause function getSlideByIndex(index) to throw an error on L52 :

TypeError: Cannot read property 'index' of undefined
    at getSlideByIndex (ui-bootstrap-tpls.js?body=1:363)
    at Scope.$scope.next (ui-bootstrap-tpls.js?body=1:391)
    at timerFn (ui-bootstrap-tpls.js?body=1:429)
    at angular.js?body=1:13331
    at Scope.$eval (angular.js?body=1:14467)
    at Scope.$digest (angular.js?body=1:14283)
    at Scope.$apply (angular.js?body=1:14572)
    at tick (angular.js?body=1:10429)
@rvanbaalen
Copy link
Contributor

Plunkr please.

@wesleycho
Copy link
Contributor

Here is a reproduction in Plunker.

@wesleycho
Copy link
Contributor

What is happening is that the carousel uses $interval to time sliding to the next slide, but if the slides disappear in the interim, then the callback fired ends up with a false assumption about the existence of an index in the slides array.

@wesleycho wesleycho self-assigned this Jun 9, 2015
@wesleycho wesleycho modified the milestones: 0.13.1 (Performance), Backlog Jun 9, 2015
@Gericho91
Copy link

currentIndex = slides.length == currentIndex ? 0 : currentIndex;
add to the 566 line in ui-bootstrap-tpls.js

function goNext(slide, index, direction) {
if (destroyed) {
return;
}
currentIndex = slides.length == currentIndex ? 0 : currentIndex;
angular.extend(slide, {direction: direction});
angular.extend(slides[currentIndex].slide || {}, {direction: direction});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants