Lev Lev - 2 months ago 12
AngularJS Question

code in directive's controller runing although it is hidden via ng-hide

In this example:

<div ng-hide="hideMe">

I would like the code in the controller for
, 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 ?


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">