AngularJS Question: Does app.js not see the services?


I tried loading a service to the app.js file and running some logic from it, using the data from a service but that didn’t work and it kept giving me the error that app.js cannot see the service.

.config(function($stateProvider, $urlRouterProvider, ServiceName) {

Is this not possible? Has anyone tried this or am I the only crazy one around here, loading services into app.js files?

I’m asking… For science… :stuck_out_tongue:

Adding a dependency to main config method?

nvm… I found the answer… This SO answer details it pretty well and in no uncertain terms that I CANNOT do this. Oh well.

Still, if some brave soul wants to answer (or you’ve found a solution), I’d like that.


what are you trying to do with the service?


I save a value in the service and depending on what the value is, I send the user to the relevant tab.

Currently, this code runs in the first controller I load. But this means the controller can be seen by the user for a very short period (which is rather irritating). I’ve been looking for a solution to run the logic before the user enters the controller and run it in app.js seemed like a great idea.


try using resolve on the controller in the ui-router - look at resolve


I’m trying this right now. But in general, resolve seems to have been used with $http and not to access a service (my service eventually just talks to LocalForage). Would that be possible?


any luck?\ getting this to work


@aaronksaunders nope… resolve just wouldn’t talk to the service. I’ve abandoned the idea for now and am waiting for the Ionic View app to relaunch so that I can test my app properly.