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>
It does not work with ng-disabled
.
I also tried with:
<li ng-class="disabled:someCondition" click="changeStatus()"> list2
</ li>
It also does not work. Can anyone suggest something?
Definition and UsageThe ng-disabled directive sets the disabled attribute of a form field (input, select, or textarea). The form field will be disabled if the expression inside the ng-disabled attribute returns true. The ng-disabled directive is necessary to be able to shift the value between true and false .
The ng-disabled Directive in AngularJS is used to enable or disable the HTML elements. If the expression inside the ng-disabled attribute returns true then the form field will be disabled or vice versa. It is usually applied on the form field (i.e, input, select, button, etc).
-- enclosing a div within the fieldset and set ng-disabled to fieldset should work.
Sometimes, we need to disable the button, and link on the click event. This task can be accomplished by implementing the ng-disabled directive that is used to enable or disable HTML elements. Parameter value: expression: It represents an expression that returns true if it sets the disabled attribute for the element.
I'm assuming it is a search box of some kind.
ngDisabled
is really used for interactive elements and not list items.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With