Is it possible to access the $ routeParams object in a $ routeProvider declaration?

In the following code:

phonecatApp.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/phones', {
        templateUrl: 'partials/phone-list.html',
        controller: 'PhoneListCtrl'
      }).
      when('/phones/:phoneId', {
        templateUrl: 'partials/phone-detail.html',
        controller: 'PhoneDetailCtrl'
      }).
      otherwise({
        redirectTo: '/phones'
      });
  }]);

Is it possible to somehow get the value "phoneId" in the url template, for example, something like this (I know that it does not work, but it explains what I ask):

      when('/phones/:phoneId', {
        templateUrl: 'partials/' + $routeParams.phoneId + '.html',
        controller: 'PhoneDetailCtrl'
      }).

The goal is to load an HTML file called phoneId.

+4
source share
1 answer
.when('/phones/:phoneId', {
    controller: 'PhoneDetailCtrl'
    templateUrl: function (params) {
        return 'partials/' + params.phoneId + '.html';
    }
})
+6
source

All Articles