angularJS - 添加具有NG选项的静态选项 [英] angularJS - add a Static option with ng-options
本文介绍了angularJS - 添加具有NG选项的静态选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用NG选项打印在我的角度应用形式的所有选项。我得到这给了我的国家名单的从我的数据库直接值:
I am using ng-options to print all the options for a form in my angular app. I get the value directly from my database which gives me a list of countries:
<select ng-options="country.country for country in countries" ng-model="selectedCountry" ng-change="updateSelectedCountry(selectedCountry)" class="form-control">
下面是加载页面时,选择犯规显示任何东西,即没有占位符,而我想打印,如无处不在的静态值,而无需将其添加到我的国家名单。
Here when the page is loaded, the select doesnt show anything, i.e. there is no placeholder whereas I'd like to print a static value like "anywhere" without having to add it in my "countries" list.
我已经试过这样:
<select ng-options="country.country for country in countries" ng-model="selectedCountry" ng-change="updateSelectedCountry(selectedCountry)" class="form-control">
<option>Anywhere</option>
</select>
但它不工作
有没有人有一个想法如何解决这个问题?
Does anyone have an idea how to solve this?
感谢
推荐答案
您总是可以只做到这一点:
You could always just do this:
<select ng-model="selectedCountry" ng-change="updateSelectedCountry(selectedCountry)" class="form-control">
<option>Anywhere</option>
<option ng-repeat="country.country for country in countries">{{country.country}}
</option>
</select>
下面是我的小提琴例如
希望这有助于!
这篇关于angularJS - 添加具有NG选项的静态选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文