0

I am calling for a modal to open with a $uibModal and i want to fill an array with integers from m to n. Because the range between the numbers is very big sometimes, the modal is opening very slow. I need to show inside the select box the values of the array. Any suggestions? this is my code:

vm.arr = [];

while (step > 0 ? max >= min : max <= min) {
      vm.arr.push(min);
      min += step;
}
  • 6
    If there are enough numbers to slow down the browser, it's unlikely to be a good user experience to have to select the number itself... – Heretic Monkey May 16 '17 at 16:36
  • 2
    Agreed. If there are that many numbers in the range, maybe you could just let the user type the number and do a range check on the result? – Mark Reed May 16 '17 at 16:39
  • @Mark Reed I think this is the best solution for now, thank you! – Trying_To_Know May 16 '17 at 16:42
  • Possible duplicate of [Create a JavaScript array containing 1...N](http://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n) – PMerlet May 16 '17 at 16:42
  • 1
    Also, it's unlikely the `while` loop that's causing the slow down. That's simple code that should work fine. It's more likely how you're binding it. For instance, try using `var arr = []; while (...) { arr.push(min); } vm.arr = arr;`. When you push items into a bound array, that triggers AngularJS to recreate the `select` over and over again. – Heretic Monkey May 16 '17 at 16:44

0 Answers0