I have one condition in controller. If the condition return true, then I have to disable all links and ng-click
s
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?
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
You can try to create your own directive, but ng-disabled
is the correct way, as JinsPeter said
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