2

我有以下代码:

<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-repeatvsng-option来做一些基本的事情,比如没有选择和做data-index. 但是,当我尝试设置模型时它不起作用......

$scope.model.RemediationCredentials = "Zoo"

有什么建议么?

4

1 回答 1

4

使用角度选择指令:

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>
于 2013-10-23T19:01:39.657 回答