简体   繁体   English

Angular js ng-class不起作用

[英]Angular js ng-class not working

I am trying to do a pagination for my list of informations. 我正在尝试对我的信息列表进行分页。 Currently, there is two buttons which are previous and next button. 当前,有两个按钮是previousnext按钮。 The previous button is working but the next button is working but its continously working. previous按钮在工作,但next按钮在工作,但仍在继续工作。 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: 这是我的controller.js代码:

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

Here's a working plunker. 这是一个正在工作的家伙。

Move the ngClick from a to li OR move the ngClass to a . ngClicka移至li ngClass移至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 . 假设您有一个定义为disabled的类。 If not, define it as follows: 如果不是,则定义如下:

.disabled {
    opacity: 0.5;
    pointer-events: none;
}

尝试使用totalitems.length - 1更改totalitems - 1 totalitems.length - 1

试试这个ng-class =“ {'disabled':currentPage == totalItems-1}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM