簡體   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