Search code examples
angularjsangularjs-ng-options

Applying ngClassEven and ngClassOdd like behavior to ngOptions


I want to add Styling to ngOptions via ngClassEven and ngClassOdd. I know they are supposed to work with ngRepeat but in the mean time i could not switch to ngRepeat. I have seen this answer but it does not corresponds to my needs.

Is it possible to apply a behavior like ngClassEven and ngClassOdd for ngOptions?

Thanks in advance.


Solution

  • you can do it in plain css

    you html

    <select class="sel" ng-options="item in items" ng-model="selected">
    

    your css

    .sel option:nth-child(even) {background: #ccc}
    .sel option:nth-child(odd)  {background: #fff}