ng-options with object data source

colefner picture colefner · Dec 5, 2013 · Viewed 56.4k times · Source

I'm struggling to understand how ng-options works with a data source. I've read the docs and I feel like I'm doing exactly what is required, but I still get problems when attempting.

I always get this error in the console:

Error:

Expected ngOptions in form of 'select (as label)? for (key,)?value in collection (track by expr)?' but got 'k as v for(k, v) in types'.

What am I doing incorrectly?

See plunkr here:

http://plnkr.co/edit/Bl6u4151KyDkxhYrsdCm?p=preview

Answer

Jayantha Lal Sirisena picture Jayantha Lal Sirisena · Dec 5, 2013

This is kind of strange, but it seems like you need to put a space after for. This works:

<select ng-model="type" ng-options="k as v for (k, v) in types">
  <option value="">Select Type</option>
</select>