0

In my controller, I have:

 $scope.sizes = {
    things: [
        'one',
        'two'
        ]
}

and in my HTML, I have

  <select ng-options="thing for thing in sizes.things"></select>

The resulting combobox has no values. However, in this case:

 $scope.things = ['one', 'two'];

  <select ng-options="thing for thing in things"></select>

The resulting combobox shows "one", "two" as its options. Can someone explain why I can't access the array within a $scope object?

5
  • That doesn't seem like it should be a problem. Can you demonstrate the problem in a jsFiddle (or some other online demo tool)? Commented Jul 10, 2015 at 22:12
  • sure! here you go Commented Jul 10, 2015 at 22:20
  • Are you really using Angularjs 1.0.3? Commented Jul 10, 2015 at 22:24
  • that fiddle is broken. angular is never being bootstrapped, and if you are using 1.4, that's definitely not the way to declare a controller. Commented Jul 10, 2015 at 22:32
  • ng-options has had a number of breaking changes over the life of angular, so if you are trying to demonstrate an issue, you should ensure that you are showing code that is compatible with the version you are trying to troubleshoot. Commented Jul 10, 2015 at 22:33

1 Answer 1

2

You were missing the ng-model attribute on your ng-options select element.

Adding ng-model="thing" gets it working...

<select ng-model="thing" ng-options="thing for thing in sizes.things"></select>

You can see a working example here.

PS It was actually not working for either the array or the object. Adding the ng-model attribute gets both working.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.