From AngularJs documentation
$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.
window.setTimeout is a JavaScript function, so whatever you use setTimeout
you must use $apply() to update the model.
Your second example wouldn't work without $apply()
, I've made a demo to clarify the $watch
and $apply
issue. Please check it.