Prevent error $digest already in progress when calling scope.$apply()