angularjs - 添加多个硬codeD选项来选择与NG-选项框 [英] angularjs - Add multiple hard-coded options to select box with ng-options
问题描述
我有一个填充选择框NG选项
。我知道你可以手动添加默认选项,像这样:
I have a select box that is populated with ng-options
. I know you can add a default option manually, like so:
<select ng-model="selectedAddress" ng-init="selectedAddress = selectedAddress || address_dropdown[0].value" ng-change="handleStoredAddressClick2()" ng-options="a.dropdown_display for a in address_dropdown" id="address_dropdown">
<option value="" ng-selected="selected">Add a new address</option>
</select>
有什么办法(以角),以添加多个选项?客户端现在都想拥有的第一个,默认选项说从地址选择,并添加上面显示新的地址选项从 NG-选项列表中的最后一个选项,所有的填充选项之后
。
(我知道我可以使用jQuery添加选项,但宁愿保持它的所有棱角如果可能的话)。
(I know I could use jQuery to add that option, but would rather keep it all angular if possible.)
推荐答案
修改2:有太多你,downvoters:您可能注意到,这个帖子是从2014年三月使用源,卢克(我不进angularJs了)
EDIT 2: Too you, downvoters: You may notice, this post is from march 2014. Use the source, Luke! (I am not into angularJs anymore)
修改:这不会工作,如果你想在模型绑定到一个非字符串作为艾美奖提到
EDIT: this wont work "If you want the model to be bound to a non-string" as Emmy mentioned!
试试这个:
<select ng-model="YourModel">
<option value="" ng-selected="selected">an option</option>
<option ng-repeat="item in items">{{item.name}}</option>
<option value="">another option</option>
</select>
有一个愉快的周末!
have a nice weekend!
这篇关于angularjs - 添加多个硬codeD选项来选择与NG-选项框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!