Check if in a $digest cycle before calling functions through $apply