[英]Get key from the ng-option angularjs
我對ionic真的很陌生,並嘗試在我的應用程序注冊頁面中為國家/地區實施下拉菜單,我能夠從響應中顯示下拉菜單中的數據,但在選擇項目時無法獲得其關鍵價值。
這是我在下拉菜單中顯示的json響應:
{
AD: "Andorra",
AE: "United Arab Emirates",
AF: "Afghanistan",
AG: "Antigua and Barbuda",
AI: "Anguilla",
AL: "Albania",
AM: "Armenia",
AN: "Netherlands Antilles",
AO: "Angola",
AQ: "Antarctica",
AR: "Argentina"
}
我正在保存的api響應如下:
$scope.results = response.data;
這是我在下拉菜單中顯示它的方式:
<select class="input-select" >
<option value="" disabled selected hidden>Country</option>
<option ng-change="selectedCountry()" ng-repeat="(key, value) in results" ng-model="country" value="{{key}}">{{value}}</option>
</select>
我只是想通過使用功能來獲取用戶選擇的國家/地區的密鑰
ng-change="selectedCountry()"
在我的HTML中。 但是這個函數沒有被調用。
任何幫助將不勝感激謝謝。
您需要在選擇時使用ngOptions指令以及ngModel:
<select class="input-select"
ng-model="country"
ng-change="selectedCountry()"
ng-options="key as value for (key, value) in results">
<option value="" disabled hidden>Country</option>
</select>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.