Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple conditions for ng-disabled

I have the following table with 3 checkboxes. I assigned each one its own model.

I have a button which I want to be disabled unless any one of the 3 checkbox models are true.

However I'm confused since I expected to use

<button " ng-disabled="!mt0 || !mt1 || !mt2">Reassign</button>

since if any of those were to be true the button should not be disabled.

However, the opposite worked:

<button ng-disabled="!mt0 && !mt1 && !mt2">Reassign</button>

Why?

See plnkr here: http://plnkr.co/edit/yURa3g0aNjDyfEvjK2D0?p=preview

like image 616
Steve Avatar asked Feb 24 '15 19:02

Steve


People also ask

How do I give conditions in NG disabled?

The 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 .

What is ATTR disabled angular?

To disable elements just use attribute disabled rather than true or false. To enable it again, you need to remove the disabled attribute. In your code [attr. disabled] is setting the value to true or false, what you need is just use [disabled] instead of [attr.


1 Answers

You can do this to achieve what you want: fiddle

<div ng-app>
    <input type="checkbox" ng-model="mt0">
    <input type="checkbox" ng-model="mt1">
    <input type="checkbox" ng-model="mt2">
    <button ng-disabled=" (mt0||mt1||mt2) ?  false : true">Reassign</button>
</div>
like image 163
Michelangelo Avatar answered Oct 09 '22 17:10

Michelangelo