[英]How to set default value to select when I am using ng-model and and ng-change?
我問這個問題是因為ng-model覆蓋了select標簽中的默認值。 因此,我需要設置<option value="-translation.published_at" selected>{{ 'Newest first' | translate }}</option>
<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>
應用ng-init
<select id="order" class="text-dark-gray" ng-model="sortedBy" ng-init="sortedBy= yourDefaultValue" ng-change="filterByDate(sortedBy)">
更改事件后在控制器端進行或操作
$scope.sortedBy= yourDefaultValue;
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";
您可以使用ng-init或內部角度控制器:
$scope.sortedBy = "your default value";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.