Imagine some heavy content that might be rendered on a web page, such as a chart. Angular gives 2 options to toggle the visibility of said content.
ng-show>
+1 on Denis's answer, but just for completeness-sake, it can even be simplified further by keeping the logic in the View without "polluting" the controller:
Heavy content
plunker
EDIT: the version above could be further improved (and simplified) with one-time binding to reduce an unnecessary $watch on once
- this will only work in Angular 1.3+:
Heavy content
The undefined
is needed to ensure that the watched value does not "stabilize" before it becomes true
. Once it stabilizes, it also loses the $watch, so it would not be impacted by any further change to show
.