1

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.

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Are you initialising the value of newempoyee.Gender?
0

Initialize newemployee.Gender to 1 instead

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.