Angularjs,使用选定的特定值填充下拉列表

Angularjs,使用选定的特定值填充下拉列表,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,在ng repeat内部,我有一个选择下拉列表,如果obj.Name1中有数据,则必须用特定的选择值填充该下拉列表,否则它应该在选项中选择默认的第一个值 <table ng-controller="TestCtrl"> <tr ng-repeat="obj in MainArray" > <td>{{$index + 1}}</td> <td ng-model="MainArray">{{obj.FirstValue}}</t

在ng repeat内部,我有一个选择下拉列表,如果obj.Name1中有数据,则必须用特定的选择值填充该下拉列表,否则它应该在选项中选择默认的第一个值

<table ng-controller="TestCtrl">

 <tr ng-repeat="obj in MainArray" >
<td>{{$index + 1}}</td>
<td ng-model="MainArray">{{obj.FirstValue}}</td>
<td>

<!-- if obj.Name1 has some value then it has to be selected in select dropdown, else default first value of dropdown must be displayed  -->
<!-- dont know how to put a condition so as to display the obj.Name1 value in the dropdown-->

<select ng-model="DropdownArray[$index]" ng-options="test.ID as test.Name for test in DropdownList" >
     <option>Default Value</option>
 </select>

</table>

我的问题是,如果
obj.Name1
包含任何值,我如何将其显示为选中的选项?

您可以创建一个匹配空字符串的选项,并且由于
ng model
中的变量不包含任何内容,它将与空值匹配,如下所示

<select ng-model="DropdownArray[$index]" ng-options="test.ID as test.Name for test in DropdownList" >
     <option value="">Default Value</option>
</select>

默认值

如何在选择下拉列表中显示obj.Name1值?(我需要DropdownArray[]用于其他目的,基本上是获取单个下拉值)您的问题是什么?如果obj.Name1包含任何值,那么我如何将其显示为选定选项例如,{“FirstValue”:“Second”,“Name1”:“two”}Name1的值为2,则应显示为选定选项(在DropdownArray中)[$index])
<select ng-model="DropdownArray[$index]" ng-options="test.ID as test.Name for test in DropdownList" >
     <option value="">Default Value</option>
</select>