Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In angularjs we are having ng-disabled directive, why ng-enabled directive is not provided by the framework as we are having ng-show and ng-hide

In AngularJs ng-enabled directive is not provided. Is there any proper reason to not providing that directive in the framework, because we are having both ng-show and ng-hide when you can just use ng-hide to achieve our goal.

It wouldn't be nice just to check ng-enabled="attribute.value === true"

instead of ng-disabled="!(attribute.value === true)"

it will increase the readability of the code.

like image 998
Avinash Solanki Avatar asked May 22 '15 10:05

Avinash Solanki


People also ask

Which of the following is true about Ng-disabled directive?

Q 9 - Which of the following is true about ng-disabled directive? A - ng-disabled directive can enable a given control.

What is Ng-disabled in AngularJS?

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 .

How do I give conditions in NG-disabled?

Or you can use ng-disabled="condition1 || condition2" , is depend of you logic conditional.


1 Answers

The reason why there is no ngEnabled directive in Angular is rather semantical - there is simply nothing corresponding to it in HTML specification. At the same time there is already ngDisabled directive that works with disabled attribute. For the same reason, there is no ngUnchecked directive, because there is already ngChecked that sets/removes checked attribute.

Now, the reasonable question: why we have both ngShow and ngHide then? Well it's just for convenience in this case I guess, because having both ngShow and ngHide is not more confusing than ngShow alone, but at the same time it's very handy to have both.

like image 158
dfsq Avatar answered Sep 21 '22 13:09

dfsq