1

I want to select particular item in dropdownlist with angularjs i used this code but it is not working

   <select class="form-control" ng-model="primaryObjectId" ng-change="getPrimaryObjectColumns()">
                <option value="{{object.id}}" ng-repeat="object in objectList">{{object.name}}</option>
            </select>

in controller.js

$scope.primaryObjectId = "3";

but is selecting first item in list i want to select 3rd item from list

2
  • is it displaying the list? Commented Aug 11, 2015 at 9:34
  • 1
    Use ng-options instead ng-repeat Commented Aug 11, 2015 at 9:35

1 Answer 1

2

You need to use ng-options with ng-model.

In many cases, ngRepeat can be used on elements instead of ngOptions to achieve a similar result. However, ngOptions provides some benefits such as reducing memory and increasing speed by not creating a new scope for each repeated instance, as well as providing more flexibility in how the 's model is assigned via the select as part of the comprehension expression.

 <select ng-options="items for items in objectList" ng-model="primaryObjectId"></select>

See example

See this example to get items based on value of option item.

Set drop down item based on id. See example

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

2 Comments

thankyou but i want to select dropdown list based on id
not like this items have a property id,name in this name is displayed in dropdownlist i want to select perticular name based on item id

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.