1

I am trying to set select list value from angular JS,which doesn't throw any exception but doesn't reflect any changes either. This is my jsp code.

<select class="form-control "  id="searchCriteriaList"
                    name="searchCriteriaList" ng-model="searchCriteriaSelect" required>
                    <option>IMEI</option>
                    <option>Registration Number</option>
                </select>

This is my angularJS code

 var selectedValue = "IMEI";
 $scope.searchCriteriaSelect = selectedValue;

This shows a blank select list. Although this code works

$scope.searchCriteriaSelect = "IMEI";

and select list shows IMEI option on page load.

But I can't assign hardcoded values. It has to be through a variable as data comes from ajax request in my code.

Please help me. Thanks in advance.

2
  • Have you tried assigning it to the first index of your list? Like searchCriteriaList[0] or perhaps when you get the result of your ajax call, you then assign the model value to the first index? Commented Dec 9, 2015 at 1:17
  • this works perfectly normally in a generic angular 1.4.8 app. plnkr.co/edit/HBN6YGdWcobUKqz7Lhe9?p=preview. Perhaps it has something to do with the version of angular you are using, or something else that is interacting with these values? Commented Dec 9, 2015 at 1:27

2 Answers 2

1

It would be better if you assign the options in the select via the ngoptions directive; https://docs.angularjs.org/api/ng/directive/ngOptions

<select ng-options="item as item for searchCriteriaList" ng-model="searchCriteriaSelect"></select>

Then you can have a explicit declaration of searchCriteriaList:

var searchCriteriaList = [];
searchCriteriaList.push("IMEI");

Then you can track by index:

$scope.searchCriteriaSelect = $scope.searchCriteriaList[0];
Sign up to request clarification or add additional context in comments.

Comments

0

try this !

<option value="IMEI">IMEI</option>
<option value="XXX">Registration Number</option>

add value="IMEI" into option attribute

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.