-2

I'm trying to develop some pagination buttons using ng-repeat like this:

<li ng-repeat="(indexN, item) in objsCh[indexO].nit | limitTo: (Math.ceil(indexN+1/10))"><a href="#">{{(Math.ceil(indexN+1/10))}}</a></li>

This code checks how many items there is in an array, divide it by 10 and create an tag with the Match.ceil result on it.

Unfortunaly, this not work properly.

PS.: in my controller I put this piece of code:

$scope.Math = window.Math;

Someone have any idea how to solve it using the code this way?

Thanks!

Bruno Ornelas
  • 331
  • 1
  • 3
  • 14
  • Well "how many items there is in an array" is not `indexN` which is the _current index_. Rather you should use `objsCh[indexO].nit.length`. – ryanyuyu Jul 22 '15 at 14:30
  • http://stackoverflow.com/questions/12740329/math-functions-in-angular-bindings http://stackoverflow.com/questions/20196954/why-math-floor-return-nothing-when-we-write-it-into-html-angular – Sergiu Paraschiv Jul 22 '15 at 14:35
  • 1
    What's the error/exception/whatever? "not work properly" won't help anyone. – Sergiu Paraschiv Jul 22 '15 at 14:41
  • If you expect a precise answer tell us what's the expecting behaviour – maurycy Jul 22 '15 at 14:42
  • ryanyuyu, it solved the limitTo issue, but I should print buttons with the values: 1, 2, 3, 4........ but with this solution I can't do that. – Bruno Ornelas Jul 22 '15 at 14:43

1 Answers1

0

Ok, I found the solution. I am not sure if it's the best but it solved my problem.

The fixed code:

<li ng-repeat="(indexN, item) in objsCh[indexO].nit | limitTo: (Math.ceil(objsCh[indexO].nit.length/10))"><a href="#">{{indexN+1}}</a></li>

I set the limitTo using the length of the array instead of index and I return the index inside each button.

Bruno Ornelas
  • 331
  • 1
  • 3
  • 14