1

I have a complex object like this

listItems = [
    { "id": 1, "name": "myname1" },
    { "id": 2, "name": "myname2" },
    { "id": 3, "name": "myname3" }
];

I want to create options from above listItems like this

<select>
    <option value="1">myname1</option>
    <option value="2">myname2</option>
    <option value="3">myname3</option>
</select>

I have used this angularjs code, its generating the correct html code but whatever I select in dropdown is not shown inside the select box

<select ng-model="iList" ng-options="item.id as item.name for item in listItems track by item.id" />

1 Answer 1

1

Assuming listItems is in the $scope

<select ng-options="item.id as item.name for item in listItems"></select>
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.