2

I have the following function in my controller...

$scope.pagerPages = function (n) {
    var i = Math.ceil(n);
    return new Array(i);
}

the n comes from an expression on the view, and can sometimes be a fraction. Which is why I've done Math.ceil on n.

Anyone know why I would be getting this error?

Invalid array length

EDIT; n is a calculation from the view

<div ng-repeat="i in pagerPages( report.TotalNumRows / report.View.PageSize ) track by $index">
...
</div>

the calculation results in 11.2, which is evidentally working, as on the page i get 12 iterations of the div element, yet it's generating this error?

5
  • 1
    what is the value of i when you get the error? Commented Jul 28, 2015 at 15:06
  • 3
    More importantly, what is n exactly? Commented Jul 28, 2015 at 15:07
  • 1
    Can n have negative values? Commented Jul 28, 2015 at 15:08
  • Did you fix this issue? I am testing code that has the same problem. Commented Apr 6, 2016 at 17:11
  • i had completely forgotten about this, yes, i discovered that the issue was a negative number. Commented Apr 8, 2016 at 15:15

1 Answer 1

3

Check the value of i. I suspect it's negative

Even if n was a string or an object it would still work. You'd only get that error is i is a negative number.

i.e. new Array({}) or new Array('ergerg') wont give you an error, but new Array(-2) will give you the error you have

Sign up to request clarification or add additional context in comments.

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.