ng-options 如何设置第一次选择总是空白 [英] ng-options how to set first select always blank
本文介绍了ng-options 如何设置第一次选择总是空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个项目中使用 angularjs,并在其中使用 ng-options 生成 .
I am using angularjs in a project and in which I am using ng-options for generating .
最初当页面重新加载并且没有选择选项元素时,生成的 html 如下所示:
Initially when the pages reload and no option element is selected the html generated like below:
<select size="3" ng-model="item" ng-options="s.name for s in itemlist">
<option value="?" selected="selected"></option>
<option value="0">Item 1</option>
<option value="1">Item 2</option>
<option value="2">Item 3</option>
</select>
但是当我选择一个元素(例如第 2 项)时,第一个空白选择消失了.我知道它的发生是因为 ng-model 是由选择值设置的.但我希望首先选择始终为空,以便用户可以重置过滤器.
But when I select an element (ex. Item 2) the first blank select is gone. I know its happening as ng-model is being set by select value. But I want first select always blank so that user can reset the filter.
提前致谢.
推荐答案
这将为您完成工作:
<select size="3" ng-model="item" ng-options="s.name for s in itemlist">
<option value="">Select Option</option>
</select>
这篇关于ng-options 如何设置第一次选择总是空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文