Navin Pawar Navin Pawar - 5 months ago 10
AngularJS Question

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>

Answer

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
}