gpt4 book ai didi

javascript - 在angularjs中选择不选择默认值

转载 作者:行者123 更新时间:2023-12-03 08:05:10 24 4
gpt4 key购买 nike

以下是我的代码摘录

   <select
ng-init="joinedStatus=0"
ng-options="joinstat.name for joinstat in joined track by joinstat.id"
ng-selected="joinedStatus==joinstat.id"
ng-model="joinedStatus">
<option>{{joinedStatus}}</option>
</select>

但仍然没有选择默认选项。

加入定义为:

$scope.joined=[{id:0,name:'否'},{id:8,name:'是'}];

最佳答案

您不应提供<option>里面selectng-options将添加指定数组中的选项。

ng-selected是没有用的。也将其删除。

所以,这会起作用

<select ng-init="joinedStatus=joined[0]"
ng-options="joinstat.name for joinstat in joined track by joinstat.id"
ng-model="joinedStatus">

</select>

因为我们已经用第 0 个数组元素初始化了模型。您将在选择中看到此选项。

关于javascript - 在angularjs中选择不选择默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34411749/

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