Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in Web Technology by (47.6k points)

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 Answer

+2 votes
by (106k points)
edited by

For working with select using AngularJS's ng-options if you need a custom title for each option, ng-options are not applicable. Instead of that, you can use ng-repeat with options. 

Looking for Angularjs material from basics! Refer to this video on Angularjs provided by Intellipaat:

You can see the code below:-

<select ng-model="myVariable">

<option ng-repeat="item in items"

value="{{item.ID}}"

title="Custom title: {{item.Title}} [{{item.ID}}]"> {{item.Title}}

</option>

</select>

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...