当 select 只有一项时,如何禁用 select 的下拉菜单

How to disable the dropdown menu of select when the select only has one item

我正在使用来自 angularstrap 的 'select' 小部件。

我想知道如何防止 select 的下拉菜单只有一项。默认只有一项selected,如何防止select上的点击事件显示下拉菜单?

它是 angularstrap 缺少的功能吗?

检查 example

中的 Single select

这不是 angularstrap 功能,但您可以使用 ng-hideng-showng-if 等属性在 select 具有只有一项。

更新: 根据您的示例,更改 Single select 部分:

<label>Single select:&nbsp;</label>
<button ng-if="icons.length > 1" type="button" class="btn btn-default" ng-model="selectedIcon" data-html="1" bs-options="icon.value as icon.label for icon in icons" bs-select>
  Action <span class="caret"></span>
</button>
<button ng-if="icons.length === 1" type="button" class="btn btn-default" ng-model="selectedIcon" data-html="1">
  {{icons[0].value}}
</button>

我无法添加齿轮图标,但我希望它很容易修复 ;)

我会像@Egan Wolf 提到的那样做,但问题是用户体验。仅仅因为数据已更改或不足以容纳 select 框而向用户显示不同的东西并不是很好。我会禁用它,这样用户会得到一个清晰的视觉反馈,he/she 不能 select 更多。