I have an Angular app which is supposed to display different pages depending on the resource in the following way:
- Given url: localhost/foo/456
- Call REST service (fooService) to get a descriptor for the foo.
- Based on the descriptor use an appropriate template.
Here's the config part (a bit of a pseudocode):
.config(['$routeProvider', '$locationProvider', 'fooService', function ($routeProvider, $locationProvider, fooService) {
$locationProvider.html5Mode();
var fooTemplateUrlSelector = function (routeParams) {
var foo = fooService.getFoo(routeParams.fooId);
switch (foo.TemplateId) {
case 1:
return 'Foo1.html';
case 2:
return 'Foo2.html';
default:
return 'Unsupported.html';
}
};
$routeProvider.when('/foo/:fooId', { templateUrl: fooTemplateUrlSelector, controller: 'FooController' })
The problem is that in the config phase I don't have access to any service ('Unknown provider: fooService'). It seems to be an Angular constraint that in the config part you're allowed to only access 'static' things. I get it.
What's the best (in terms of best practices) solution to this problem?
The templates might differ a lot, so I don't want to have one html file with a lot of "if TemplateId == 1, then display_some_markup else if TemplateId == 2 then display_something_else".
providerinstead of makingservicewhich would be easily available in config phase