title: AngularJs: $routeProvider with dynamic controller name won't load
body: <p>The AngularJs documentation says you can specify either a string or a function for controller &amp; 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:</p>
  
  <pre><code>$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 + "'" );
          }
        } );
  </code></pre>
  
  <p>When loading the application I get the following error:</p>
  
  <pre><code>Error: [$injector:unpr] Unknown provider: paramProvider &lt;- param
  </code></pre>
  
  <p>Am I missing anything obvious here? Switching the controller to use a string rather than a function fixes the issue.</p>
  
  <p>Looks like some people have run into this issue before (eg. <a href="https://stackoverflow.com/questions/18423054/dynamically-loading-the-controller-in-angularjs-routeprovider">here</a>), but a I'm confused why this doesn't work as the documentation suggests that it should.</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>Joseph.</p>