Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Support ngOptions #46

Closed
devesh opened this issue Jul 10, 2013 · 17 comments
Closed

Support ngOptions #46

devesh opened this issue Jul 10, 2013 · 17 comments

Comments

@devesh
Copy link

devesh commented Jul 10, 2013

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.

@itsdrewmiller
Copy link

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.

@rdniller
Copy link

+ 1 on this request.

@rdniller
Copy link

This angularjs select2 directive supports ng-options:

ngyn

@jrust
Copy link

jrust commented Oct 2, 2013

+1 as well to reduce the number of scopes when using a bunch of select2 boxes on the page.

@tlrjs
Copy link

tlrjs commented Jan 24, 2014

+1 on supporting ng-options

@jkarttunen
Copy link

+1 support for ng-options.
It gets dirty to work with some select boxes that support returning whole object with ng-model, and then ui-select2 that returns only strings for selected item.

@dtabuenc
Copy link

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.

@nfantone
Copy link

nfantone commented Jun 6, 2014

+1

@ptanov
Copy link

ptanov commented Jun 6, 2014

Are there any plans to fix this issue?

@chatellier
Copy link

+1

@dtabuenc
Copy link

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:

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

@geminiyellow
Copy link

thanks @dtabuenc , it working.

@mukgupta
Copy link

@dtabuenc : Thanks! your script saved my day.

@igler
Copy link

igler commented Sep 6, 2014

+1

@bountin
Copy link

bountin commented Sep 9, 2014

+1
With ngOptions one can bind a complex object as model like "country as country.name for country in countries". This is not possible with ng-repeat and ng-value.
A workaround is to bind on $index and resolve the repeated objects by hand (or register a watcher for it) but this solution is not as nice as angular's.

@wodka
Copy link

wodka commented Jan 5, 2015

@dtabuenc this works like a charm :)

@PowerKiKi
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests