5

I am attempting to have my data show up in the list as follows:

<option value="4351">Atlanta</option>

Here is my object.

$scope.cityList = {
    4351:{name:"Atlanta", short="atlanta"},
    7355:{name:"Baltimore", short="baltimore"},
    1212:{name:"Chicago", short="chicago"},
    4398:{name:"Dallas", short="dallas"}
};

HTML
This worked with just key-value pairs, but now the "value" is an object

<select class="select-city" ng-model="myCity" ng-options="name for (city, name) in cityList"></select>

So my question is this:
How can I populate the ng-options in this case?

2
  • 1
    name.name for (city, name) in cityList? Commented Apr 30, 2015 at 19:10
  • 1
    Thanks, that totally works! Can you explain how and I'll accept your answer? Commented Apr 30, 2015 at 19:14

1 Answer 1

5

Use name.name for (city, name) in cityList - the name.name in this case refers to the name property of the new object you introduced, which itself is unfortunately named name.

The documentation is a bit mystic but you can perhaps also rename it to something like value.name for (key, value) in cityList.

Sign up to request clarification or add additional context in comments.

1 Comment

Name is named name? Funny, nevername me

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.