我有以下代码:
<select ng-model="model.RemediationCredentials" name="remediationCredential" id="remediationCredential">
<option value="0">---</option>
<option ng:repeat="cred in credentialsList"
data-index="{{$index}}" value="{{cred.Value}}">{{cred.Key}}</option>
</select>
和credentialsList
看起来像:
credentialsList = [ { Key: "Panda", Value: "Zoo: } ]
我想我需要使用ng-repeat
vs ng-option
来做一些基本的事情,比如没有选择,然后执行data-index
。但是,当我尝试设置模型时,它不起作用......
$scope.model.RemediationCredentials = "Zoo"
有什么建议吗?
答案 0 :(得分:4)
使用Angular Select指令:
http://docs.angularjs.org/api/ng.directive:select
应该看起来像这样:
<select ng-model="model.RemediationCredentials" name="remediationCredential" id="remediationCredential" ng-options="cred.value as cred.key for cred in credentialsList">
<option value="0">---</option>
</select>