1

I am trying to do a pagination for my list of informations. Currently, there is two buttons which are previous and next button. The previous button is working but the next button is working but its continously working. Actually, I want it to be disabled once the end of the list has been reached. But now I can still click on the next button.

How do I solve this bug?

This is my pagination code:

<div ng-show="filteredItems > 0">

<ul class="pagination" page="currentPage">
    <li ng-class="{disabled: currentPage == 1}">
        <a href ng-click="prevPage()">« Prev</a>
    </li>

    <li ng-class="{disabled: currentPage == totalItems - 1}">
        <a href ng-click="nextPage()">Next »</a>
    </li>
  </ul>
</div>

This is my controller.js code:

$scope.nextPage = function () {
    if ($scope.currentPage < $scope.totalItems - 1) {
            $scope.currentPage++;
            console.log($scope.totalItems);
        }
    };
}

3 Answers 3

2

Here's a working plunker.

Move the ngClick from a to li OR move the ngClass to a. For the first case:

<li ng-class="{disabled: currentPage == totalItems - 1}" ng-click="nextPage()">
    <a>Next »</a>
</li>

And this is assuming you have a class defined called disabled. If not, define it as follows:

.disabled {
    opacity: 0.5;
    pointer-events: none;
}
Sign up to request clarification or add additional context in comments.

7 Comments

move the ng-click to the li containing the anchor tag
i guess the problem is in the totalItems
my currentPage value is 1 and my totalItems value is 1000
exactly, the condition is never getting true and thats why the disable class isn't getting applied.
Quotes aren't needed around disabled; it's a Javascript object literal, in which keys work just fine unquoted (within limits).
|
0

Try changing totalitems - 1 with totalitems.length - 1.

1 Comment

can you make js fiddle for it
0

try this ng-class="{'disabled': currentPage == totalItems - 1}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.