![](/img/trans.png)
[英]Cannot select default value in dropdown using ng-model and ng-repeat or ng-select in AngularJS
[英]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.