From Angular docs :
$ apply () is used to execute an expression in angular from outside the angular frame. (For example, from browser events DOM, setTimeout, XHR or third-party libraries). Because we call in the angular structure we need to execute the correct life cycle exception handling, clock execution.
The documentation also contains pseudo-code:
function $apply(expr) { try { return $eval(expr); } catch (e) { $exceptionHandler(e); } finally { $root.$digest(); } }
In short, $apply
evaluates the expression and starts the digest loop, making angular execute all registered observers and update any kind of bindings.
Finally, you said that you use $apply
to update bindings for your models, but this is only required when the update is from outside Angular. In most cases, you do not need to call it manually.
source share