Load file on memory before any controller is loaded



I need persistence on my application and I use ngCordova file plugin: http://ngcordova.com/docs/plugins/file/.

I need to know if its possible to load a file before any controller is loaded (the plugin read files asynchronously) and one of the data that is in the persistence layer is the user token to make API calls, and if it’s logged or not and i need to know if the user is logged at $ionicView.beforeEnter event to redirect the user to another view.

Any Idea?



Maybe you could have an abstract state that would be the parent of all your other states, in this “root state” you could then use resolve to load your file. This is usually what is done for authentication/authorizaition.


But the fact that the file api is asynchronous I can’t be sure that i have the data when the abstract controller is finished, not?

There is a way?



That’s what angualr-ui router’s resolve is made for unless I misunderstood your problem.
Resolve is not included in controller.