1

When I use select option, the first option of ng-option shows always blank till I select the value. I have tried option also:

<select class="form-control" ng-model="userDetails.selectedtimezone">
 <option ng-repeat="selecttimezonelist in timezones" ng-selected="userDetails.selectedtimezone == selecttimezonelist.id"  value="{{selecttimezonelist.id}}">{{selecttimezonelist.timezone}}</option>
</select>
cdomination
  • 605
  • 1
  • 7
  • 25

2 Answers2

0

Angular will usually auto fill in the first option of a drop down menu with a blank value if it hasn't been initialized to a value or if you have set it to a value that is not within the list of values it can select from.

You should take a look at what value you are initializing its variable to or, if you haven't yet, initialize the variable to one of the values in the list to select from.

Joffutt4
  • 1,418
  • 14
  • 15
0

By angular way

<select class="form-control" ng-model="userDetails.selectedtimezone" ng-init="selecttimezonelist = timezones[0]">
    <option ng-repeat="selecttimezonelist in timezones" ng-selected="userDetails.selectedtimezone == selecttimezonelist.id"  value="{{selecttimezonelist.id}}">{{selecttimezonelist.timezone}}</option>
</select>

And then use css

select option:empty {
    display:none
}
Vijay Dohare
  • 731
  • 5
  • 22
  • 1
    It's doubtful, that this example is "by angular way". Using ng-init, hidding empty option with css, neglecting ng-options directive, unnecessary `ng-selected`. I consider this answer as wrong. – Serhii Holinei Jun 16 '16 at 19:13