Angular using $routeParams in Page title

Viewed 1370

I found this answer in another SO question. But i would like to also use route parameters in some of the page titles.

If i have a $routeProvider like this:

$routeProvider.when('/demo/:name/:idNumber', {title : ' - :name', templateUrl: 'partials/details.html', controller: 'AppDetails'}); 

how do I match the :name in the title to the :name in the location? I tried the following

.run(['$location', '$rootScope', '$routeParams', function($location, $rootScope,   $routeParams) {
  $rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
    if(current.$$route.title.contains(":")){
        //Not sure how to get the route param using the title param string
    }else{
      $rootScope.title = current.$$route.title;
    }
  });
}]);

but I don't know how to get a variable from the routeParams using a string.

3 Answers
Related