javascript - select box default value
某草草
某草草 2017-06-12 09:30:32
0
3
832

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

某草草
某草草

reply all(3)
仅有的幸福

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

小葫芦

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];
typecho

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..

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template