How $digest() and $apply() works in Angular