V
V
Vlad Tokarev2015-08-28 18:04:14
Angular
Vlad Tokarev, 2015-08-28 18:04:14

How to wait for core data to load before path processing starts?

I app.jshave code like this:

vtTmModule.config(function ($routeProvider, $locationProvider, $httpProvider) {
  $routeProvider
    .when('/someUrl', {
      controller: 'SomeController'
      ,templateUrl: 'someTpl.html'
      ,resolve: {}
    })
    .when('/anotherUrl', {
      controller: 'AnotherController'
      ,templateUrl: 'anotherTpl.html'
      ,resolve: {}
    });
}).run(function ($rootScope, $routeParams, $location, UserLoader) {
  UserLoader.then(function(result) {
    $rootScope.users = result;
  });
  // Получение прочих данных с сервера через промисы
});

Accordingly, when the page is updated run(...), the template and controller are loaded for the corresponding URL. run(...)I'm trying to load common data used for most paths . The problem is that this data is sometimes loaded later than the controllers and templates in which it should be used.
How to prevent routing processing before all data is received in run(...)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-08-28
@Vadiok

1) we take this logic to the service
2) we store the promise in the service
3) we use this promise in resolvers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question