title: AngularJS routes and Ajax data on route change
body: <p>I am failing to understand the Angular way to do the following...</p>
  
  <p>I have a router configured, once the route is changed, and the templateUrl is supplied I would like to make an Ajax call to fetch some JSON data.</p>
  
  <p>Notice that, i do not want to wait to fetch the template and than use the controller to fetch the JSON data because that is two serial HTTP calls. I want to fetch the JSON data in parallel with fetching the template. Is there a well known pattern to do this?</p>
  
  <p>Correct me if I am wrong... For now, I understand that I should use the resolver in which I would call an a "data provider", which will fire an HTTP call to get the JSON data. This data than will be available to the controller. So something like this...</p>
  
  <pre><code>app.config(['$routeProvider', 'data', function( routeProvider, dataProvider ) {
  
    routeProvider.
        when('/reports/:reportName', {
            templateUrl: function( urlData ) {
                return "/some/url/" + urlData.reportName + "/content";
            },
            resolve: {
                reportData: function() {
                    return dataProvider.getData();
                }
            },
            controller: 'reportRoutingCtrl'
        });
  }]);
  app.controller('reportRoutingCtrl', ['$scope', 'reportData', 'reportName', function( scope, reportData ) {
      console.dir( reportData );
  }]);
  </code></pre>
  
  <p>Is this the correct pattern to follow? If so, how can I get access to the 'urlData' object in the resolver?</p>
  
  <p>Thank you for the help!!</p>