AngularJS ng-disabled not working with list items

Hmahwish picture Hmahwish · Jan 22, 2015 · Viewed 28k times · Source

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?

Answer

Nicow picture Nicow · Sep 26, 2015

I guess you want to disable the onclick if someCondition is true. This should work:

<ul>
  <li>list1</li>
  <li  ng-click="someCondition || changeStatus()">list2</li>
  <li  >list3</li>
</ul>

So if someCondition is true it will not execute changeStatus() since an OR statement will not execute the next statement when the previous is already true.