angularjs - angularJs 的国家选择控件

标签 angularjs country-codes

我需要在我的 angular-breeze 应用程序中使用国家/地区下拉菜单,我尝试了以下操作:
https://github.com/banafederico/angularjs-country-select

这里的问题是它没有国家/地区/代码对,只有国家/地区的长名称,我不想将其保存到数据库中。我是否可以使用其他任何 Angular 指令/服务来填充国家/地区的下拉列表?我已经做了一些挖掘,但我没有找到任何现成的国家/地区选择选项。

最佳答案

您可以使用 ng-repeatng-options指令并创建国家下拉列表。通过这种方式,您可以完全控制。如果需要此元素在许多地方使用,您可以将其创建为指令。

演示:http://plnkr.co/edit/2y9Jcektl8g2L0VoNQyp?p=preview

使用 ng-option 指令

<select ng-model="country" ng-options="country.name for country in countries track by country.code">
  <option value="">-- Select a Country --</option>
  </select>

使用 ng-repeat 指令:
<select ng-model="country">
    <option value="">-- Select a Country --</option>
    <option ng-repeat="country in countries" value="{{country.code}}">{{country.name}}</option>
</select>

Controller 中的国家/地区范围:
    $scope.countries = [ 
        {name: 'Afghanistan', code: 'AF'},
        {name: 'Åland Islands', code: 'AX'},
        {name: 'Albania', code: 'AL'},
        {name: 'Algeria', code: 'DZ'},
        {name: 'American Samoa', code: 'AS'}
    ];

关于angularjs - angularJs 的国家选择控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28404361/

相关文章:

javascript - AngularJS错误: $injector:unpr Unknown Provider with using ui-router

java - 来自国家名称的 ISO2 国家代码

web-applications - 荷属安的列斯群岛于 10 年 10 月 10 日解散,如何更改国家下拉列表?

ios - 确定 iOS 区域 "Europe"的国家代码

c# - 国家代码列表 - C#

javascript - 使用 Angular 指令加载部分不在第二次加载 View 时呈现

javascript - ng-repeat 中按键自定义对象排序

angularjs - 使用空对象进行 Angular 排序

javascript - 如何从 Firebase 获取服务器时间