我到处搜索过,很难说我做错了什么。我正在尝试使用控制器中的值填充选择组件
我的控制器代码段
$scope.sTypes=
[
{name:'PGD',id:1},
{name:'MSC',id:2},
{name:'PHD',id:3},
{name:'DBA',id:4}
]
$scope.selectedType={};
我的网页选择
<select ng-model="selectedType" ng-option="sType.name for sType in sTypes">
<option>--- Select Scholarship ---</option>
</select>
正在渲染的内容
<select
ng-model="selectedType"
ng-option="sType.name for sType in sTypes"
class="ng-pristine ng-valid">
<option value="? object:005 ?"></option>
<option value="--- Select Scholarship ---">
--- Select Scholarship ---
</option>
</select>
任何帮助将不胜感激,因为这开始惹恼我。
我自己还没有看到确切的事情,但我发现将value=""
添加到空选择选项中可以工作:
<select ng-model="selectedType" ng-option="sType.name for sType in sTypes">
<option value="">--- Select Scholarship ---</option>
</select>
如果 ng-model
为 null,这将是默认选择选项。
因此,我会像上面一样配置 html,然后像这样初始化selectedType
:
$scope.selectedType=null;