I\'ve been using $scope.$apply() to update the bindings for my models when I receive data through websockets in my Angular apps and it works. But what does it a
From the Angular docs:
$apply() is used to execute an expression in angular from outside of the angular framework. (For example from browser DOM events, setTimeout, XHR or third party libraries). Because we are calling into the angular framework we need to perform proper scope life-cycle of exception handling, executing watches.
The documentation also provides a pseudo-code of it:
function $apply(expr) {
try {
return $eval(expr);
} catch (e) {
$exceptionHandler(e);
} finally {
$root.$digest();
}
}
In short, $apply evaluates an expression and triggers a digest cycle, making Angular execute all registered watch listeners and update any view bindings.
Finally, you've said that you've been using $apply to update the bindings for your models, but that is only required when the update comes from outside Angular. In most cases you don't need to call it manually.