Question

Trying to create a set of select options from a simple list, instead of an array or an object that would have keys. All the docs & examples I find are pertaining to keyed data types.

$scope.numbers = ['tweedle', 'beetle', 'battle'];

Using the code below, the select list renders fine on load.

<select ng-model="fox" ng-options="item for item in fox"></select>

After you make a selection, it splits the selection value into a comma separated list. Try selecting and item, then selecting a different item.

I'm sure it has something to do with the binding, but I can't put my finger on it:

http://jsfiddle.net/LR6DL/1/

Was it helpful?

Solution

It's because you're setting the ng-model of the select to fox. fox is also what your options are set to, so your options array is being over written with the selected value (string) - which then gets split to letters to satisfy the ng-options directive.

Short solution:

Change your ng-model to selection and your input to selection as well.

Demo: http://jsfiddle.net/LR6DL/2/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top