Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<optgroup> Support? #47

Closed
Siyfion opened this issue Mar 26, 2014 · 6 comments
Closed

<optgroup> Support? #47

Siyfion opened this issue Mar 26, 2014 · 6 comments

Comments

@Siyfion
Copy link

Siyfion commented Mar 26, 2014

Assuming that I have a collection of elements with a group property, is there a way to use 'ng-options' in such a way that it will produce correct '' tags? As I can't think of a way of doing this...

@robinfhu
Copy link

If you're options array has a "group" attribute, you can define ng-options like so:

ng-options='o.value as o.label group by o.group for o in model.options'

@ilanbiala
Copy link

@Siyfion does this work?

@dkavanagh
Copy link

Sort of... doesn't honor "as" and uses index as value instead. Trying to see what's angular's fault though: https://docs.angularjs.org/api/ng/directive/ngOptions

@webeng
Copy link

webeng commented Sep 14, 2015

The "group by" worked for me.

@bent10
Copy link

bent10 commented Feb 25, 2016

You can use "group by" expression

{
  "teams": [
    {"name": "Johan", "email": "johan@mail.com", "group": "one"},
    {"name": "Mala", "email": "mala@mail.com", "group": "two"},
    {"name": "Saimin", "email": "saimin@mail.com", "group": "one"},
    {"name": "Dolah", "email": "doll@mail.com", "group": "three"},
    {"name": "Abah", "email": "abah@mail.com", "group": "three"}
  ]
}

then use

ng-options="t.name group by t.group for t in teams"

@leocaseiro
Copy link
Owner

Thanks @robinfhu @bent10

I've made a plunkr for it: http://plnkr.co/edit/j0yIif?p=preview

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

No branches or pull requests

7 participants