David
David

Reputation: 974

AngularJS and select2 from Angular-UI: Selected option different from what user picks

When a user selects an option, a different option shows up as the selected option. This only occurs with select2 enabled. However, ng-model will correctly behave as expected, so the select will display a different option to what ng-model reports.

Notably, if i click on the option a second time, it will correctly select and display the item I want and the selection and model will be in sync

example
<select class="form-control" ui-select2 class="select2El" ng-model="schedule.deviceid" ng-options="device.deviceid as device.name for device in devices"></select>

Where devices is an array of objects.

if I click the first option shown (say option with id: 1), a completely unrelated option (option with id: 30) will display as the selected item. Ng-model will show option 1.

if I click on the intended first option a second time, it will now correctly display.Ng-model will still show option 1.

Versions:

Upvotes: 0

Views: 642

Answers (1)

Quad
Quad

Reputation: 1718

ui-select2 docs says it's not compatible with ng-options.

github.com/angular-ui/ui-select2#working-with-dynamic-options

you should use ng-repeat.

Upvotes: 1

Related Questions