It may seem challenging to make the route config object dynamic, but in reality, it's quite static. The configuration is set only once when the route is defined, and it does not change based on future route parameter values.
If you need to update the page title based on the route parameter value, you can utilize the $routeParams
service to access the parameter and the $document
service to modify the title. This can be done within a controller or using a resolve
statement.
For instance, consider the following implementation:
$routeProvider.when('/movies/:type', angular.extend({
templateUrl: 'pages/movies/movies.html',
controller: 'MoviesCtrl',
resolve: {
title: ['$routeParams','$document', function ($routeParams, $document) {
var title = 'Filmes-' + $routeParams.type;
$document.title = title;
return title;
}]
}
}, defaults));
This approach also works effectively within a controller context.
A couple of observations regarding your code:
- Concerning the inclusion of a
title
property in the route config object, this practice might not align with AngularJS documentation recommendations. It's not referenced in the official documentation.
- The naming of the second argument,
defaults
, within the angular.extend
function could potentially lead to confusion as it resembles the $routeParams
service. Consider utilizing a clearer name like routeDefaults
for better clarity.