Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE 8 selecting n+1 index

Tags:

angularjs

With IE 8, if I have a select list like so...

            <select required ng-options="n for n in monthNumbers" ng-model="month">
            </select>

...then Angular adds a blank first option in. Then when I select any option, IE 8 will select the option that comes after it. So if I select month 1, it will select month 2.

If I add an initial element like this...

        <select required ng-options="n for n in monthNumbers" ng-model="month">
           <option></option>
        </select>

... then the problem is fixed. However then Angular won't remove the empty first element when any other item is selected which is the behavior I want.

Is there a decent way around this?

like image 408
Ian Warburton Avatar asked Jul 17 '13 14:07

Ian Warburton


2 Answers

I added ng-disabled="true" to the manually added initial options and that stops people from selecting them in IE 8.

https://stackoverflow.com/a/2031748/221683

like image 75
Ian Warburton Avatar answered Nov 15 '22 05:11

Ian Warburton


Use ng-options like this:

<select required ng-options="month.value as month.label for month in months" ng-model="month"></select>
like image 40
EpokK Avatar answered Nov 15 '22 04:11

EpokK