From my understanding, re-evaluation occurs during a digest
in Angular.
The framework goes through all values in the scope to check for any changes.
Deep nesting doesn't seem to pose much of an issue because it only compares against the value used in the view (unless you add a watcher on the deeply nested object).
Some advice:
Avoid using methods for conditions within the view:
<span data-ng-hide="someFunction()"></span>
The function will be called on each digest
, which can impact performance.
Avoid using watchers on complex object structures:
This will recursively evaluate the entire structure, causing slowness.
Consider using directives instead of {{}}
:
Why? For example: angular-translate:
It offers both a filter and a directive for the same purpose.
<span>{{'WELCOME'|translate}}</span>
<span data-translate="'WELCOME'"></span>
The filter gets re-evaluated with every digest
, whereas the directive watches the passed value and only re-evaluates when necessary.
Prefer using data-ng-if
over ng-Show/Hide
(Now that data-ng-if
is available):
ng-Show/Hide
hides DOM elements using display:none;
in CSS.
Hidden elements still get evaluated and their data may change even if not visible.
ng-if
completely removes the DOM element, avoiding unnecessary re-evaluation within it.