Load file on memory before any controller is loaded


#1

Hello,

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?

Thanks!


#2

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.


#3

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?

Thanks!!


#4

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

http://learn.ionicframework.com/formulas/data-the-right-way/