问题描述
我在禁用列表中的项目时遇到问题。
I am facing a problem with disabling a item in the list.
<div id="searchdropdown">
<ul>
<li>list1</li>
<li ng-disabled="someCondition" ng-click="changeStatus()">list2</li>
<li>list3</li>
</ul>
</div>
它不适用于 ng-disabled
。
我也尝试过:
<li ng-class="disabled:someCondition" click="changeStatus()"> list2
</ li>
它也不起作用。任何人都可以提出建议吗?
It also does not work. Can anyone suggest something?
推荐答案
我假设它是某种搜索框。
I'm assuming it is a search box of some kind.
ngDisabled
实际上用于交互元素而不是列表项。
ngDisabled
is really used for interactive elements and not list items.
您可以使用 ng-if
或 ng-hide
从列表中完全删除这些项目:
You can use ng-if
or ng-hide
to remove those items completely from the list:
<li ng-if="!condition" ng-click="changeStatus()">item</li>
<li ng-hide="condition" ng-click="changeStatus()">item</li>
您可以使用 ngClass
来应用特定的禁用时禁用类以使其显示为禁用:
You can use ngClass
to apply a specific class when disabled to make it appear disabled:
<li ng-class="{'disabled':condition}" ng-click="changeStatus()">item</li>
如果您想要一个项目可见但不能点击,您可能需要做一个黑客攻击如果项目被禁用或使事件沉没,请重新打开搜索框。
If you want an item to be visible but not click-able, you may have to do a hack like re-opening the search box if the item is disabled or sinking the event.
这篇关于AngularJS ng-disabled不使用列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!