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 8737359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:30:11+00:00 2026-06-13T10:30:11+00:00

I have read about it in other posts, but I couldn’t figure it out.

  • 0

I have read about it in other posts, but I couldn’t figure it out.

I have an array,

$scope.items = [
   {ID: '000001', Title: 'Chicago'},
   {ID: '000002', Title: 'New York'},
   {ID: '000003', Title: 'Washington'},
];

I want to render it as:

<select>
  <option value="000001">Chicago</option>
  <option value="000002">New York</option>
  <option value="000003">Washington</option>
</select>

And also I want to select the option with ID=000002.

I have read select and tried, but I can’t figure it out.

  • 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-13T10:30:12+00:00Added an answer on June 13, 2026 at 10:30 am

    One thing to note is that ngModel is required for ngOptions to work… note the ng-model="blah" which is saying “set $scope.blah to the selected value”.

    Try this:

    <select ng-model="blah" ng-options="item.ID as item.Title for item in items"></select>
    

    Here’s more from AngularJS’s documentation (if you haven’t seen it):

    for array data sources:

    • label for value in array
    • select as label for value in array
    • label group by group for value in array
      = select as label group by group for value in array

    for object data sources:

    • label for (key , value) in object
    • select as label for (key , value) in object
    • label group by group for (key, value) in object
    • select as label group by group for (key, value) in object

    For some clarification on option tag values in AngularJS:

    When you use ng-options, the values of option tags written out by ng-options will always be the index of the array item the option tag relates to. This is because AngularJS actually allows you to select entire objects with select controls, and not just primitive types. For example:

    app.controller('MainCtrl', function($scope) {
       $scope.items = [
         { id: 1, name: 'foo' },
         { id: 2, name: 'bar' },
         { id: 3, name: 'blah' }
       ];
    });
    
    <div ng-controller="MainCtrl">
       <select ng-model="selectedItem" ng-options="item as item.name for item in items"></select>
       <pre>{{selectedItem | json}}</pre>
    </div>
    

    The above will allow you to select an entire object into $scope.selectedItem directly. The point is, with AngularJS, you don’t need to worry about what’s in your option tag. Let AngularJS handle that; you should only care about what’s in your model in your scope.

    Here is a plunker demonstrating the behavior above, and showing the HTML written out


    Dealing with the default option:

    There are a few things I’ve failed to mention above relating to the default option.

    Selecting the first option and removing the empty option:

    You can do this by adding a simple ng-init that sets the model (from ng-model) to the first element in the items your repeating in ng-options:

    <select ng-init="foo = foo || items[0]" ng-model="foo" ng-options="item as item.name for item in items"></select>
    

    Note: This could get a little crazy if foo happens to be initialized properly to something “falsy”. In that case, you’ll want to handle the initialization of foo in your controller, most likely.

    Customizing the default option:

    This is a little different; here all you need to do is add an option tag as a child of your select, with an empty value attribute, then customize its inner text:

    <select ng-model="foo" ng-options="item as item.name for item in items">
       <option value="">Nothing selected</option>
    </select>
    

    Note: In this case the “empty” option will stay there even after you select a different option. This isn’t the case for the default behavior of selects under AngularJS.

    A customized default option that hides after a selection is made:

    If you wanted your customized default option to go away after you select a value, you can add an ng-hide attribute to your default option:

    <select ng-model="foo" ng-options="item as item.name for item in items">
       <option value="" ng-if="foo">Select something to remove me.</option>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read about application object in android site but I couldn't understand. What
According to Apple documentation and other documentation I have read about on disk encryption
I have read this article from High Scalability about Stack Overflow and other large
I have read about continuency parser and dependency parser. but confused which could be
I've read a few other posts like this one about avoiding repetition in Java
I have read countless blogs, posts and StackOverflow questions about the new features of
I've read quite some posts about webkit browsers having issues with images. I couldn't
I've read all the posts I could find about this issue, but, to date,
I have read about a lot of people having problems with the browser not
I have read about session fixation and from what I understand it forces a

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.