我有一个国家列表(带有代码和名称),当列表展开时,我想显示“code + name”(例如“+44 United Kingdom”)但是当我们选择一个国家时,只显示代码(“+44”)。 Angular ngOptions可以做什么?angularjs select ngoptions - 以不同的格式显示选定的值
<select ng-model="userData.phoneCode" ng-options="(c.countryCallingCode.replace('00', '+') + ' ' + c.countryName) for c in countries track by c.countryId">
<option value="" disabled selected data-i18n="Country"></option>
</select>
在控制器的国家列表的形式:
countries = [
{
"countryCallingCode":"0033",
"countryCode":"FR",
"countryId":123,
"countryName":"France"
},
]
我想这一点:
我在谷歌一直在寻找,我试图创建这样的指令(我在angularjs中的级别是中等),但我没有找到解决方案,总是将选定的选项显示为“代码+名称”。
有什么想法?
您能显示国家列表吗? (我的意思是你的控制器中的对象数组) –
@LenilsondeCastro我编辑我的文章与国家名单 – josekron
我测试了你的代码,它的工作正常检查了这一点https://jsfiddle.net/tt27bjsn/1/ –