<select ng-if="PF_Set.PF.length > 0">
<option ng-if="PF_Set.showPleaseSelect && PF_Set.PF.length>1">Please Select</option>
<option ng-repeat="PF in PF_Set.PF" ng-click="doSomething()">{{::PF.SelectedDisplayValue}}</option>
</select>
列表包含SelectedDisplayValue和isSelected等值。列表中只有一个项目具有isSelected = true。我可以将其作为下拉列表中的选定值吗?
已更新 - 仍有问题
<select ng-model="PF_set.PF" ng-attr-id="{{item.Index + '_' + PF_set.Type}}" ng-if="PF_set.PF.length > 0 >
<option ng-selected="PF.isSelected" ng-repeat="PF in PF_set.PF">{{PF.isSelected}} : {{::PF.SelectedDisplayValue}}</option>
</select>
更新 - 剩余1个小问题,需要添加&#34;请选择&#34;如果没有选择
,则列在列表顶部删除了ng-model。这肯定会引起很多与ng-repeat
的混淆<select ng-attr-id="{{item.Index + '_' + PF_set.Type}}" ng-if="PF_set.PF.length > 0 >
<option ng-selected="PF.isSelected" ng-repeat="PF in PF_set.PF">{{PF.isSelected}} : {{::PF.SelectedDisplayValue}}</option>
</select>
答案 0 :(得分:1)
您可以使用ng-selected
指令:
example
<option ng-repeat="PF in PF_Set.PF"
ng-selected="PF.isSelected">
{{PF.SelectedDisplayValue}}
</option>