我问这个问题是因为 ng-model 覆盖了 select 标签中的默认值。所以我需要设置 <option value="-translation.published_at" selected>{{ 'Newest first' | translate }}</option>
成为默认值。这是我的代码:
<div class="filter__order filter--select p-rel">
<select id="order" class="text-dark-gray" ng-model="sortedBy" ng-change="filterByDate(sortedBy)">
<option value="-translation.published_at" selected>{{ 'Newest first' | translate }}</option>
<option value="translation.published_at">{{ 'Oldest first' | translate }}</option>
</select>
</div>
最佳答案
Assign value to the ng-model of select
<select required="required" class="form-control control-sm" ng-change="settingtestValue(ItemValue)" ng-model="ItemValue" name="info_bcsWorkItem">
<option value="">--Select--</option>
<option ng-repeat="bcsItem in bcsWorkItemList" value="{{ bcsItem }}" >{{ bcsItem }}</option>
</select>
$scope.ItemValue= "your value you want to assign";
关于javascript - 当我使用 ng-model 和 ng-change 时如何设置默认值来选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48824495/