How to set the selected item?

I have a problem with setting the selected item in angularjs’s select directive.

 <select ng-change="_change()" ng-model="default_job_value">
    <option value="no">default value</option>
    <option ng-repeat="job in jobs" ng-value="{{job}}">part-time({{job}})</option>

How to change the selected item?

If you are trying to set one of the array items, you would put the value of the job that you want to select in ng-select. In the below code, ‘tester’ is the value of the job to select:

<select ng-change="_change()" ng-model="default_job_value">
    <option value="no">default value</option>
    <option ng-repeat="job in jobs" ng-value="{{job}}" ng-selected="job == 'tester'">part-time({{job}})</option>

Or if you want to select the default value option, just put ng-selected="true" on that tag:

<option value="no" ng-selected="true">default value</option>

Many thanks, @brandyshea.

1 Like

Here is my code its not working even i fallowed ur code

select ng-change=“aitypeSelectedChild(viewlisttype)” ng-model=“viewlisttype”>
option ng-repeat=“type in ailisttypes” ng-value="{{type}}" ng-selected=“type == viewlisttype”>{{type}}

It is also possible to write:

<select ng-model="myModel.selectObj" ng-options=" for object in objects track by"></select>

After defined a send(mymodel) method in controller we can set onclick event on a button ng-click=“send(myModel)”

In the method we now can find the option object selected.
This work for me.

select ng-model=“selectedMenu” ng-change=“aitypeSelected(selectedMenu)” class="">
option class=“mobile-font-Msize” value=‘My Action Items’>My Action Items
option class=“mobile-font-Msize” value=‘All Action Items’>All Action Items
optgroup label=“Saved Search” ng-show=“your_saved_searches.length > 0”>
option value="{{ saved }}" ng-repeat=“saved in your_saved_searches”>{{ saved.search_name }}

First option i can accept il use ng-option what u said , but what about sencond option there also one more ng-repeat .