Reputation: 708
I have a Business dropdown, that is being populated with a list of objects. All I want to do is when I load the page I have business pre-selected with the data coming from my service.
Let's go through details
json array of objects for the select option
[{"code":"MA","value":"Main"},{"code":"TL","value":"Toll Free"},{"code":"AP","value":"After Hour"},{"code":"FX","value":"Fax"},{"code":"DR","value":"Direct"},{"code":"WB","value":"Web"},{"code":"EM","value":"Email"}]
code for select option
<select id="selectOption" ng-model="company.business" ng-options="option as
option.value for option in businessDropdownValues" class="form-control form-
control-sm input-sm"> </select>
Please tell me how do I get the pre-selected option if the company.business
is received as one of the objects received from the list provided above?
Thanks
Upvotes: 1
Views: 34
Reputation: 888
You have to use like this.
<select id="selectOption" ng-model="company.business" ng-options="option.value for option in businessDropdownValues track by option.code" class="form-control form-
control-sm input-sm"> </select>
Upvotes: 0
Reputation: 888
You can also do like this :
<select id="selectOption" ng-model="company.business" ng-options="
option.value for option in businessDropdownValues track by option.id" class="form-control form-
control-sm input-sm"> </select>
Upvotes: 1