Ritesh Gupta
Ritesh Gupta

Reputation: 171

Selected option not working on select dropdown in AngularJS

I am getting some strange behavior on my Dropdown control in Angular Js application. Now selected="selected" is not working and default selected values are blank.

I have also been facing another issue on the edit click button. It is associated to gender and should be selected automatically on dropdown but it is still not working.

<select ng-model="newemployee.Gender" class="form-control">
   <option value="1" selected="selected">Male</option>
   <option value="0">Female</option>
</select>

Is it due to Angular.js file which I have updated to latest version? Because such issues arose after updating.

Upvotes: 1

Views: 1240

Answers (3)

BATMAN_2008
BATMAN_2008

Reputation: 3520

I was facing this issue and tried a lot finally this worked for me

<select ng-model="newemployee.Gender" class="form-control">
   <option value="1" ng-selected="newemployee.Gender = '1'">Male</option>
   <option value="0">Female</option>
</select>

Upvotes: 0

miquelarranz
miquelarranz

Reputation: 894

I have had problems with the selected options sometimes and what I use to do is using ng-selected like this:

<option value="1" ng-selected="newemployee.Gender == '1'">Male</option>

So the option will be selected if both values are equal. You can find more information here: ng-selected Documentation

Upvotes: 1

Kobi Cohen
Kobi Cohen

Reputation: 678

Initialize newemployee.Gender to 1 instead

Upvotes: 0

Related Questions