Dustin Butler
Dustin Butler

Reputation: 897

Angular ng-option not creating any options

I've been looking at this for too long and can't figure out why the options aren't showing up. Using 1.2.26

{{students}}
<select name="student" ng-options="i.id as i.first_name for i in students"></select>

So this outputs a select but no options. students is populated and displays as

[{"first_name":"Student","last_name":"Seven","email":"","order":"0","id":11,"rLevel":2},{"first_name":"Student","last_name":"Eight","email":"","order":"6","id":12,"rLevel":2},{"first_name":"Student","last_name":"Six","email":"","order":"2","id":10,"rLevel":2},{"first_name":"Studen","last_name":"Four","email":"","order":"1","id":8,"rLevel":2}]

I know angular is initialized and students is an array of objects. This loop just below the select outputs and functions as it should.

    <li ng-repeat="student in students">
      <a href="#" ng-click="addStudent(student.id)">{{student.first_name}} {{student.last_name}}</a> <span ng-show="student.id == class.current_student.id"></span>
    </li>

Upvotes: 1

Views: 27

Answers (1)

GregL
GregL

Reputation: 38103

There is no ng-model attribute on your select. ng-options only works with ng-model, otherwise it has nowhere to bind to.

Also, I just noticed line 388 of the select directive source. That relies on the ngModelController's render functionality to actually populate the options in the DOM.

Upvotes: 1

Related Questions