Home  >  Q&A  >  body text

javascript - select box default value

This is the html part of select

<select class="form-control w-searchbar-select" ng-model="aa" ng-init="aa='请选择设备状态'" >
   <option ng-repeat="data in  ProcedureList" value="{{$index}}">{{data}}</option>
</select>

The following is the equipmentProcedureList part defined

$scope.equipmentProcedureList = ["请选择设备状态", "注册", "使用中", "故障", "报废"];

The effect of the current writing method on the page is:
No items are selected in the select box and it is blank.
However, if the value="{{$index}}" in option is removed, it will be displayed normally.
Seek the guidance of the great God

某草草某草草2658 days ago801

reply all(3)I'll reply

  • 仅有的幸福

    仅有的幸福2017-06-12 09:32:32

    The desired page effect is to select "Please select device status" by default, and the value of the remaining items is $index. Finally, ng-repeat is used to implement the above functions.
    $scope.equipmentProcedureList = ["Please select device status", "Registered", "In use", "Fault", "Scrap"];

    The above are the drop-down options of select, predefined.

    $scope.aa="请选择设备状态";

    Specify the items selected by default here

    <select class="form-control w-searchbar-select" ng-model="aa" >
       <option value="请选择设备状态"></option>
       <option ng-repeat="data in  equipmentProcedureList" value="{{$index}}">{{data}}</option>
    </select

    This is the HTML part

    reply
    0
  • 高洛峰

    高洛峰2017-06-12 09:32:32

    angularJS recommends using ng-options to create drop-down menus

    <select ng-model="aa" ng-options="y for (x, y) in ProcedureList"></select>
    
    $scope.ProcedureList = ["请选择设备状态", "注册", "使用中", "故障", "报废"];
    
    //我一般使用下面这样初始化不用ng-init,这样我觉得好改一点,想初始化几就写数组的索引
    $scope.aa = $scope.ProcedureList[0];

    reply
    0
  • typecho

    typecho2017-06-12 09:32:32

    The value of value in option is a number, and when initialized, value='Please select device status', there is no corresponding display value with this value..

    reply
    0
  • Cancelreply