Load configuration data in Angular Applicatoin

In my angular application, I want to load some user specific configuration data from server, if user authorized. This data will use all over the application. I have implemented cookie base token authentication. How can I delay application until this data loading complete?


You can use resolve in route. Example from ng-doc:

app.config(function($routeProvider, $locationProvider) {
   .when('/Book/:bookId', {
    templateUrl: 'book.html',
    controller: 'BookController',
    resolve: {
      // I will cause a 1 second delay
      delay: function($q, $timeout) {
        var delay = $q.defer();
        $timeout(delay.resolve, 1000);
        return delay.promise;

Instead of timeout promise you can return any promise what you wish. In this case your controller will be started after route.resolve promise resolving.

Also look at this answer. It looks like very relevant for your case.

Leave a Reply

Your email address will not be published. Required fields are marked *