0

I'm making a pagination system with the "next" button. The "next" button should increase the page.currentPage variable, but it should not do anything when it reached the maximum numPagesTotal.

How do I add this condition to the following ng-click expression:

<a ng-click="page.currentPage = page.currentPage + 1">Next</a>

I figured that I need another block variable that is set to true when page.currentPage === numPagesTotal, and do something like below:

<a ng-click="block || page.currentPage = page.currentPage + 1">Next</a>

How do I set block in the ng-click?

jsFiddle, for reference

5
  • Can you explain what is the expected result? if the current page is the last page you dont want to show the next button? Commented Feb 20, 2015 at 17:37
  • I would move all this logic to the controller so your UI just has ng-click=pageUp(). Commented Feb 20, 2015 at 17:39
  • if 'currentPage == NumPagestotal', so maybe desactive the ng-click or something, because now they currentPage can be higher to number pages and this is bad Commented Feb 20, 2015 at 17:41
  • 1
    @marjes, I have edited your question to better explain the objective. Commented Feb 20, 2015 at 17:43
  • Ben, I thought of that option, but i need work with multiple tables, i need create Page1_UP, Page2_UP, Page3_up....etc, and multiple vars and i dont wanna make that Commented Feb 20, 2015 at 17:44

3 Answers 3

1

You are approaching the problem correctly. You don't even need the extra block variable. Just do this:

<a ng-click="page.currentPage === numPagesTotal || (page.currentPage = page.currentPage + 1)">next</a>

But I would recommend, for clarity of the View, to make this determination in the controller:

$scope.next = function(){
   if ($scope.page.currentPage < $scope.numPagesTotal){
      $scope.page.currentPage++;
   }
}

and just call that function:

<a ng-click="next()">next</a>
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, it work too, but i try it, only in html side,
This is a cleaner way and separates the logic from the view. Much better to go this way than doing it in the HTML. IMHO
0

I think this does what you want.

<a ng-click="page.currentPage >= numPagin || (page.currentPage=page.currentPage+1)">next</a>

1 Comment

i hate "(", I try to do the same but without the parentheses, thanks Nicholas , this work
0

This may help you

{{(curPage*pageSize)+1}}-{{records=pageSize>count?count:(curPage == pagesCount-1) ? count:(curPage + 1)*pageSize}} of {{ count }}

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.