-
Notifications
You must be signed in to change notification settings - Fork 442
Support ngOptions #46
Comments
As far as I can tell, this actually worked fine a few months ago. It is broken in the latest version, though. I was using the value as an object, applying a filter, and loading the whole array dynamically via ajax. |
+ 1 on this request. |
This angularjs select2 directive supports ng-options: |
+1 as well to reduce the number of scopes when using a bunch of select2 boxes on the page. |
+1 on supporting ng-options |
+1 support for ng-options. |
The underlying problem is that with ng-options the value in the model is usually not the same as the actual value in the element. Whenever a change is made in the underlying model, ui-select2 tries to tell select2 about it by calling select2("val", controller.$viewModel) I think a better approach is to let select2 handle that itself. The angular select with the ng-options is still present and working, so it's just a matter of telling select2 to re-read our select and let it figure out which option is selected from there. You can easily do that by triggering a change event on our select. I've gotten this to work on some of our projects by replacing a few of the explicit value sets with tElem.trigger('change') and removing the initial: e.m.select2('data', controller.$modelValue); I think taking this approach would likely simplify the rest of the ui-select2 directive (probably eliminating a lot of the code for handling multi-selects etc....) I'm perfectly willing to make the changes and submit a pull request, but I'd like to get some feedback and make sure there's no other things that would be impacted. |
+1 |
Are there any plans to fix this issue? |
+1 |
I haven't had time to add documentation or any sort of build system, but I plan to add soon. If you don't mind using an undocumented script you can try this here: https://github.com/splendidcode/ng-select2 It allows the use of ng-options and makes the use of selct2 much more transparent. I hope to document this this weekend and make it more of an official release. Here's some examples of usage: |
thanks @dtabuenc , it working. |
@dtabuenc : Thanks! your script saved my day. |
+1 |
+1 |
@dtabuenc this works like a charm :) |
This project is deprecated. Fixes and new features are very unlikely to happen. You should instead consider a migration to https://github.com/angular-ui/ui-select. |
Like https://github.com/localytics/angular-chosen.
Alternatively, if there's a very good reason why ngOptions can't or shouldn't be supported that would not be obvious to users of this library, add the explanation the documentation.
The text was updated successfully, but these errors were encountered: