Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8123747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:16:25+00:00 2026-06-06T06:16:25+00:00

I am trying to create a select element that has a list of numbers

  • 0

I am trying to create a select element that has a list of numbers 1 to pages where pages is a variable that is the number of pages I have. What i don’t know how to do is to structure the ng-options expression so that it will give me the numbers I need. Here is what I have so far

<select ng-model="page" ng-options="???"></select>

what do I need to put in the ng-options expression in order for it to create my select like

<select>
    <option value="1">1</option>
    ...
    <option value="35">35</option>
</select>

do I need to create a function that returns an array of numbers and use it in there somehow or is there an easier way to do this?

any help would be greatly appreciated.

Thanks

EDIT

After posting my question i figured out one way to do it by creating a function called Range in my controller that takes two numbers and returns an array with all the values in that range.

$scope.Range = function(start, end) {
    var result = [];
    for (var i = start; i <= end; i++) {
        result.push(i);
    }
    return result;
};

then in the HTML I did

<select ng-name="page" ng-options="page for page in Range(1, pages)"></select> 

Is this the simplest way to do this or is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:16:27+00:00Added an answer on June 6, 2026 at 6:16 am

    Your way works fine. Another option that came to my head is to use a filter, so you don’t have to pollute your controller with Range.

    JS:

    var myApp = angular.module('myApp', []);
    myApp.filter('range', function() {
      return function(input, min, max) {
        min = parseInt(min); //Make string input int
        max = parseInt(max);
        for (var i=min; i<max; i++)
          input.push(i);
        return input;
      };
    });
    

    HTML:

    <select ng-model="page" ng-options="n for n in [] | range:1:30"></select>
    

    Example: http://jsfiddle.net/N3ZVp/1/

    P.S. in your example in your main post, you didn’t put var in front of i. So i is declared as a global variable in your example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to create a select command to query the database I have and
I am trying to create a select list starting from the current date of
I have a DataGridView with a checkbox column. I'm trying to create a select/deselect
I'm trying to create an element that contains a form so it can be
i am trying to create a select element with JS or even edit an
I'm trying to create an outlook style To: / recipients list when I select
I am trying to create two select lists both filled with the same times.
I'm new to this so bear with me. I'm trying to create a select
I'm trying to create a custom SELECT query to find my Personal Best races
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.