I'd like to have a "Global function" called the first time I launch my AngularJS application, or every time I refresh the page.
This function will call my server with $http.get() to get global information necessary to use my application. I need to access $rootScope in this function. After that, and only after this request finished, I'm using app.config and $routeProvider.when() to load the good controller.
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/',
{
/**/
});
}]);
I don't want the application do something before this action is finished. So I guess I have to use a "resolve", but I don't really know how to use it.
Any idea?
Thanks!
$httprequest before running yourconfigblocks. Therunblocks will run immediately after theconfigblocks, which is the soonest point you can do this. Also, you shouldn't store the data in$rootScope, but in a service. Why do you feel you need the info before setting up routing?$routeProviderruns; they're called a bit later. You should be fine with arunblock. Theresolveruns before the view is visible: demo. So your translation service can do its magic there, if necessary. But this belongs in a service and not on $rootScope - it won't change when it's visible in the view.