Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Js :Conditionally how to disable all button and links?

I have one condition in controller. If the condition return true, then I have to disable all links and ng-clicks

How we can do :-

Controller : $scope.disableActions = true;

In HTML

<button type="button" ng-click="ignoreAndRedisplay()" ng-disabled="disableActions">OpenClick</button>

So by doing this I have to write everywhere ng-disabled="disableActions", it will be redundant , How we can improve this for n number of button and links?

like image 477
Ravi Ubana Avatar asked Dec 19 '22 07:12

Ravi Ubana


2 Answers

What I'll suggest you to do for such cases would be, just put those all buttons inside single fieldset and apply ng-disabled over that fieldset, the controls which are inside that field set will automatically get disabled if ng-disabled expression gets evaluated to true

<fieldset ng-disabled="disableActions">
   <button type="button" ng-click="ignoreAndRedisplay()">OpenClick</button>
   <button type="button" >Some Other button</button>
   <button type="button" >One more button</button>
   ...
</fieldset>

Demo Here


As in comment you OP asking for disabling anchor tag. Basically you can't disable anchor tag. You could try below hack to make it working.

fieldset[disabled] a { 
   pointer-events: none;
}

Plunker

like image 99
Pankaj Parkar Avatar answered Dec 24 '22 02:12

Pankaj Parkar


You can try to create your own directive, but ng-disabled is the correct way, as JinsPeter said

like image 43
Ferus7 Avatar answered Dec 24 '22 00:12

Ferus7