angularJs的国家选择控制

前端之家收集整理的这篇文章主要介绍了angularJs的国家选择控制前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要在我的angular-breeze应用程序中使用国家/地区下拉菜单,并尝试使用以下内容
https://github.com/banafederico/angularjs-country-select

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

@H_403_7@ 您可以使用ng-repeat或ng-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>

控制器中的国家范围:

$scope.countries = [ 
        {name: 'Afghanistan',code: 'AF'},{name: 'Åland Islands',code: 'AX'},{name: 'Albania',code: 'AL'},{name: 'Algeria',code: 'DZ'},{name: 'American Samoa',code: 'AS'}
    ];
原文链接:https://www.f2er.com/angularjs/141526.html

猜你在找的Angularjs相关文章