I'm trying to figure out how to resolve a promise before creating my topmost controller. I'm using ui.router so I know how to resolve promises for the controllers for my different routes. But I don't know how to resolve it before my first controller gets loaded.
This is an extract of my index.html:
<html lang="de" x-ng-app="myapp">
<body x-ng-controller="MainController">
...
<div id="header" x-ng-include="'top.html'"></div>
...
<div id="viewDiv" ui-view></div>
...
</body>
</html>
I want to load the current season (and other data that rarely ever changes) from the server and have it injected into the controller for my top.html header and for some of my view controllers. I have a service that loads my current season and returns a promise:
services.factory('RestAccess', function(Restangular) {
return {
loadCurrentSeason : loadCurrentSeason
};
function loadCurrentSeason() {
return Restangular.one('season','current').get();
}
});
And I'd like to have the RESOLVED promise from this function injected in my MainController:
controllers.controller('MainController', function($scope, currentSeason, SomeService) {
$scope.season = currentSeason;
$scope.stuff = SomeService.loadStuff(currentSeason);
});
how can I configure this? This is for the Controller responsible for the body-element. So I'm not using any routing here yet.
I'd like something like
resolve: {
currentSeason : function(RestAccess) {return RestAccess.loadCurrentSeason();}
}
But I don't know where to put this.