Navin Pawar
Navin Pawar

Reputation: 11

Angularjs, select option first is always blank untill selection

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>

Upvotes: 1

Views: 920

Answers (2)

Vijay Dohare
Vijay Dohare

Reputation: 741

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
}

Upvotes: 0

Joffutt4
Joffutt4

Reputation: 1458

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.

Upvotes: 0

Related Questions