gpt4 book ai didi

javascript - AngularJS 使用 ng-model 和 ng-repeat 而不是 ng-option 选择默认值

转载 作者:行者123 更新时间:2023-11-29 18:20:05 25 4
gpt4 key购买 nike

我有以下代码:

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

$scope.model.RemediationCredentials = "Zoo"

有什么建议吗?

最佳答案

使用 Angular 选择指令:

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>

关于javascript - AngularJS 使用 ng-model 和 ng-repeat 而不是 ng-option 选择默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19550074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com