In my angular application, there is a controller that requires server-side initialization to happen before it is instantiated. I need this initialization process to be done synchronously so that the data can be fetched prior to the controller being called. Typically, I achieve this by synchronously loading and injecting data into controllers using routeProvider in the application configuration:
$routeProvider
.when('/Home', {
templateUrl: 'default/home', controller: 'homeController',
resolve: { 'InitPageData': ['initPageService', function (initPageService) { return initPageService.init("home/initpage"); }] }
})
However, I have one particular controller that does not have a specified route or templateUrl associated with it. This controller is part of a shared layout page used across multiple pages and routes. I attempted the following approach thinking that everything passing through the '/' route would go through it, but it did not work as expected:
.when('/', { // doesn't work
controller: 'appController',
resolve: { 'AppData': ['initPageService', function (initPageService) { return initPageService.init("something/initpage"); }] }
})
I am unaware of all the routes that will utilize this specific controller and I do not want to manually handle each one. Is there a way to universally resolve data and inject it into a controller regardless of where it is invoked? Any help on this matter would be greatly appreciated.