0

In this example:

<div ng-hide="hideMe">
   <my-directive></my-directive>
</div>

I would like the code in the controller for myDirective, not to run when hideMe === true.

Is there a way to do this rather than wrapping all the code of the controller in an if (!hideMe === true) statement ?

Lev
  • 13,856
  • 14
  • 52
  • 84

2 Answers2

1

ngHide simply hide the element, but if you want it not to be run you should use ngIf instead. According to the docs, ngIf removes or recreates a portion of the DOM tree (i.e., no element, no directive and no controller) but ngHide only change its visibility.

<div ng-if="hideMe">
   <my-directive></my-directive>
</div>
lenilsondc
  • 9,590
  • 2
  • 25
  • 40
0

You should actually go for ng-if directive as the the code inside does not get evaluated if the condition is false. You could refer to the following link for better understanding.

what is the difference between ng-if and ng-show/ng-hide

Community
  • 1
  • 1
Pankaj Kumar
  • 871
  • 5
  • 12