Elnaz Elnaz - 7 months ago 17
HTML Question

AngularJS: Set value for options in ng-options

I have boolean property for Customer called

IsMarried


I want to use
<select>
tag as bellow:

<select name="isMarried" id="isMarried" class="form-control" ng-model="customer.isMarried" ng-options="statue for statue in maritalStatues"></select>


How should I change the ng-options, since I want to set
1
for
Yes
and
0
for
No
in options. what should i do?

Answer

You could have 0 & 1 for respective statuses

Markup

<select name="isMarried" id="isMarried" 
   class="form-control" ng-model="customer.isMarried" 
   ng-options="statue.value as statue.description for statue in maritalStatues">
</select>

Code

$scope.maritialStatus = [ { value : 1, description : "Yes"}, {value : 0, description : "Unmarried"}];