Lev Lev - 1 year ago 52
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 ?

Answer Source

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">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download