AngularJS does not set a drop-down value for a logical model field

Although my model contains a boolean, below code is displayed true:

{{ moduleDAO.includeIntermediate }}

following HTML code:

<div class="form-group" ng-class="{'has-error': ModuleDAOForm.includeIntermediate.$invalid}">
    <label for="includeIntermediate" class="col-sm-2 control-label">Include Intermediate</label>
    <div id="includeIntermediateControls" class="col-sm-10">
    <select id="includeIntermediate" name="includeIntermediate" class="form-control" ng-model="moduleDAO.includeIntermediate" >
        <option value="">Choose a value</option>
        <option value="false">false</option>
        <option value="true">true</option>
    </select>
    </div>
</div>

displays a dropdown without any meaning, why?

BTW. The above code was generated by the JBoss Forge AngularJS forest plugin.

+4
source share
2 answers

It seems that AngularJS has a problem with choosing an option before hand if the value is boolean. However, it works if you use ng-optionsto define your parameter tags:

controller

$scope.options = [
    {value: '', label: 'Choose a value'},
    {value: false, label: 'false'},
    {value: true, label: 'true'},
];

HTML

<select ng-options="o.value as o.label for o in options"></select>

, !? , .

+8

.

<select ng-model="currentInvite.isLegal">
         <option value="1" ng-selected="currentInvite.isLegal">Yes</option>
         <option value="0" ng-selected="!currentInvite.isLegal">No</option>
</select>
+2

All Articles