
Stefan R. answered 02/28/20
Senior Web Developer with the urge to spread knowledge
I guess what you want to consider is where you want to react on an error.
In your later example,
you have no way of knowing whether the output is valid or not, while with your first example
you handle the error in a more controlled way.
However, my question is why you place your callback function into the service at all. You are creating bottlenecks with asynchronicity that aren't providing any advantage.
I assume the following scenarios:
- The need for custom reactions on an error in a controller will eventually arise.
- Bindings to the scope will be dependent on the outcome of a service call
So writing your services like this:
and using them in your controllers like this:
is likely the easiest and cleanest solution.