LOTUSMS LOTUSMS - 27 days ago 12
AngularJS Question

Angular next and prev navigation math logic

This is probably a piece of cake for you math gurus. The prevSlide goes back fine 3-2-1-3-2... etc. Regardless of the point of entry. But the nexSlide starts out 1-2-3 and then it just 2-3-2-3...I'm sure it's my math

$scope.currentIndex = 0;
$scope.setCurrentSlideIndex = function (index) {
$scope.currentIndex = index;
};
$scope.isCurrentSlideIndex = function (index) {
return $scope.currentIndex === index;
};
$scope.prevSlide = function () {
$scope.currentIndex = ($scope.currentIndex > 0) ? --$scope.currentIndex : $scope.slides.length - 1;
};
$scope.nextSlide = function () {
$scope.currentIndex = ($scope.currentIndex < $scope.slides.length -1) ? ++$scope.currentIndex : 1;
};


Help!

Answer
$scope.nextSlide = function () {
    $scope.currentIndex = ($scope.currentIndex < $scope.slides.length -1) ? ++$scope.currentIndex : 0;
};

You just need to change the 1 to a 0 at the end of this line. index 1 as you have it now is actually the 2nd slide.

Slide #: 1 -- 2 -- 3
Index #: 0 -- 1 -- 2
Comments