The AngularJs documentation says you can specify either a string or a function for controller & templateUrl in the route object when configuring the $routeProvider, however I'm running into an issue when using a function to dynamically determine the controller based on $location parameters. I have the following route configuration:
$routeProvider
.when( '/workspace/:workspaceId/product/:productId/item/:itemType/:itemId/edit', {
templateUrl: function ( param ) {
switch ( param.itemType ) {
case 'topic':
return 'topic.tpl.html';
case 'course':
return 'course.tpl.html';
}
throw new Error( "Unknown product item type '" + param.itemType + "'" );
},
controller: function ( param ) {
switch ( param.itemType ) {
case 'topic':
return 'TopicController';
case 'course':
return 'CourseController';
}
throw new Error( "Unknown product item type '" + param.itemType + "'" );
}
} );
When loading the application I get the following error:
Error: [$injector:unpr] Unknown provider: paramProvider <- param
Am I missing anything obvious here? Switching the controller to use a string rather than a function fixes the issue.
Looks like some people have run into this issue before (eg. here), but a I'm confused why this doesn't work as the documentation suggests that it should.
Any help would be greatly appreciated!
Joseph.