[英]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.
这仅在启用select2的情况下发生。 However, ng-model will correctly behave as expected, so the select will display a different option to what ng-model reports.
但是,ng-model将正确执行预期的操作,因此选择将显示与ng-model报告的选项不同的选项。
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 值得注意的是,如果我第二次单击该选项,它将正确选择并显示我想要的项目,并且选择和模型将同步
<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. 如果我单击显示的第一个选项(例如ID为1的选项),则一个完全不相关的选项(ID为30的选项)将显示为所选项目。 Ng-model will show option 1.
Ng模型将显示选项1。
if I click on the intended first option a second time, it will now correctly display.Ng-model will still show option 1. 如果我第二次单击预期的第一个选项,它将现在正确显示.Ng-model仍显示选项1。
Versions: 版本:
ui-select2 docs says it's not compatible with ng-options. ui-select2文档说它与ng-options不兼容。
github.com/angular-ui/ui-select2#working-with-dynamic-options github.com/angular-ui/ui-select2#working-with-dynamic-options
you should use ng-repeat. 您应该使用ng-repeat。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.