The right way: Calling API Functions (or Service Functions) from the Controllor

Hi guys,

I really loved the article Resolving Data the Right Way

However, if we take it a little bit further and really want the controller to stay as “dumb” as possible, I am stuck when I want to call a service function from within the controller.

For example I have an email view with a button “archive”. I do have a service “emailService” that could provide that function. But then I would of course have to inject the service into the controller and all the benefits from “Resolving data the right way” would be gone.

How do you guys structure your stuff when you want to access service or api functions from within the controller?

Best,
Frank

You inject the service into the resolve function. If you find that you are injecting a lot of services into resolve, then maybe you need to create another service that encapsulates some of the functionality.

Thanks Aaron, makes perfect sense.

One more question regarding resolving data:

I just investigated some performance issues and noticed that the state change also calls the service (in the resolve function) when ionic caching is enabled (and the data is not passed to the controller anyways) .

Does anyone have an idea how to clever solve this architectural? As a workaround I could of course pass the service into the controller like Aaron described but following the “Resolving Data the Right way article” I was wondering if there is another solution to that.

Cheers, F-