角度添加字符串:选项前面

时间:2015-11-17 09:30:14

标签: angularjs angularjs-scope

角度代码

            $scope.booleans = [ {
                "name" : "True",
                "value" : "true"
            }, {
                "name" : "False",
                "value" : "false",
            } ];

HTML

<select ng-model="field.insertable" class="form-control" ng-show="editMode"
ng-options="boolean.value as boolean.name for boolean in booleans"></select>

结果HTML

<select ng-model="field.insertable" ng-options="boolean.value as boolean.name for boolean in booleans" class="form-control ng-pristine ng-valid ng-touched" tabindex="0" aria-hidden="false" aria-invalid="false">
        <option value="?" selected="selected"></option>
        <option value="string:true" label="True">True</option>
        <option value="string:false" label="False">False</option>
 </select>

所以问题是

  • field.insertable来自后端的值为false。如何设置正确的值。
  • 为什么选项值为value="string:true"

enter image description here

1 个答案:

答案 0 :(得分:0)

你写过字符串值 - &#39; true&#39;并且&#39; false&#39; ,而是写布尔值:

 $scope.booleans = [ {
            "name" : "True",
            "value" : true
        }, {
            "name" : "False",
            "value" : false
        } ];