2

Is there a way to globally resolve a service for all the routes in AngularJs?

Let's say I need to get configuration from a Web Service for all the routes. Can we do something like the following pseudo-code?

$routeProvider
  .when('*', {
      resolve: {
         config: function(myConfigService) {
             return MyConfigService.getConfigPromise();
         }
      }
})
Tohid
  • 6,175
  • 7
  • 51
  • 80
  • 1
    Not in ngRoute. Use angular-ui-router which allows nested routes and resolve of parent is passed to all descendents – charlietfl Jul 15 '16 at 23:34
  • @charlietfl can you write your comment as the answer with a sample code so I mark it as the right answer? – Tohid Jul 17 '16 at 02:06

1 Answers1

1

ui-router might do the job instead. You can read up the difference between ui-router and ngRoute here:

What is the difference between angular-route and angular-ui-router?

Community
  • 1
  • 1