繁体   English   中英

AngularJS使用ng-model和ng-repeat代替ng-option选择默认值

[英]AngularJS select default value with ng-model and ng-repeat instead ng-option

我有以下代码:

<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来做一些基本的事情,例如no selection和data-index 但是,当我尝试设置模型时,它不起作用...

$scope.model.RemediationCredentials = "Zoo"

有什么建议么?

使用角度选择指令:

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM