gpt4 book ai didi

angularjs - angularJs 的国家选择控件

转载 作者:行者123 更新时间:2023-12-04 10:03:50 26 4
gpt4 key购买 nike

我需要在我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com