Ng-选择选项值

时间:2014-09-06 02:17:21

标签: javascript angularjs

我正在尝试创建ng-select以选择您所在的国家/地区并通过相关的国家/地区代码。我有一个哈希,但我不确定它是否正确。

<select ng-model="myCountry" ng-options="country.name group by country.iso for country     in countries" placeholder="Country">


</select>
$scope.countries= [{name: 'Canada', iso: 'CA'}, {name: 'United States', iso: 'US'}];

如何将'iso'作为带有'name'的值传递,而且我似乎无法在国家/地区的占位符处将其设置为默认值。

如果我不够清楚,请告诉我

2 个答案:

答案 0 :(得分:0)

试试这个,

 <select ng-model="myCountry" ng-options="country.iso as country.name group by country.iso for country     in countries" placeholder="Country">
       <option value="">Country</option>
 </select>

答案 1 :(得分:0)

我想你可能想要这个表达式的语法:

<select ng-model="myCountry" ng-options="country.iso as country.name for country in countries" placeholder="Country">
  <option style="display:none" value="">Country</option>
</select>   

鉴于您的group by每个项目看起来都是唯一的,我猜你真的不希望它作为select分组