JC Borlagdan JC Borlagdan - 5 months ago 7
AngularJS Question

How to dynamically make the option selected if it's equal to something?

I'm not good at jQuery or HTML I want to select the option depending on the value passed from an ajax call. The following is what's inside my html

<label class="item item-input">
<input id="" type="text" required ng-model="Data.CompanyTitle">
<select style="width: 100%">
<option>Partner</option>
<option>System</option>
<option>Council</option>
</select>
</label>


Data.CompanyTitle
passes either Partner, System or Council. I want the option to be selected depending on what the value of
Data.CompanyTitle
is.

Answer

You can give the select a model and if the value of the option is equal to your variable it gets auto selected

<select ng-model="selectModel">
    <option value="dummy">dummy</option>
</select>

and when you set $scope.selectModel = 'dummy' you can see dummy selected

Comments