angularjs - 自定义DropDownList如何设置默认值检查

angularjs - 自定义DropDownList如何设置默认值检查

问题描述:

这是我的HTML代码。这是我自定义的DropDownList。有人可以建议我如何在下面的情况下设置默认选项之一吗?angularjs - 自定义DropDownList如何设置默认值检查

<div class="dropdownlistheader" ng-click="toggle('subdiv','item')"> 
    <input type="text" readonly="readonly" class="dropdownlistinput" value="{{selectedItemValuesDisplay}}" /> 
</div> 
<div id="ddl123" ng-show="showItemOptions" class="dropdownlist"> 
    <div ng-show="showItemOptions" ng-repeat="option in ItemTypeDDL"> 
     <input type="checkbox" ng-model="selected[$index]" ng-click="toggleItemSelection(option.TypeID, option.TypeName)"> {{option.TypeName}} 
    </div> 
</div> 

基于对这些问题提供的有限的细节,我会建议如下:

<div id="ddl123" ng-show="showItemOptions" class="dropdownlist" ng-init="selected[0] = true"> 
    <div ng-show="showItemOptions" ng-repeat="option in ItemTypeDDL"> 
     <input type="checkbox" ng-model="selected[$index]" ng-click="toggleItemSelection(option.TypeID, option.TypeName)"> {{option.TypeName}} 
    </div> 
</div> 

ngInit指令将在selected标志列表中选择的第一要素,通过设置阵列的第一个索引为true