2

I have a simple json

    {
      "optgroup1" : ["option11", "option12", "option13"],
      "optgroup2" : ["option21", "option22", "option23"]
    }

I want to display this as select using angular ng-options as below:

<select>
<optgroup label="optgroup1" value="optgroup1">
<option>option11</option>
<option>option12</option>
<option>option13</option>
</optgroup>
<optgroup label="optgroup2" value="optgroup2">
<option>option21</option>
<option>option22</option>
<option>option23</option>
</optgroup>
</select>

Is it possible to use ngOptions (label group by group for (key, value) in object ) here?

Saravanan S
  • 1,021
  • 1
  • 10
  • 24
  • You need to change your JSON data : try this link- http://stackoverflow.com/questions/18615624/angularjs-ng-options-with-group – Mahaveer Jain Sep 06 '15 at 19:15
  • Thanks Mahaveer for the comment. But i dont want to add the group name in all rows. It looks like we have to build optgroup and option through ng-repeat instead of using ngOptions. – Saravanan S Sep 07 '15 at 03:44

1 Answers1

0

in that case you have to know your optgroup what you are going to receive from your json data and check condition for it in your ng-repeat.