Angular 在页面标题中使用 $routeParams [英] Angular using $routeParams in Page title

查看:24
本文介绍了Angular 在页面标题中使用 $routeParams的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一个 SO 问题中找到了这个答案.但我也想在一些页面标题中使用路由参数.

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

如果我有这样的 $routeProvider:

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

如何将标题中的 :name 与位置中的 :name 匹配?我尝试了以下

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;
    }
  });
}]);

但我不知道如何使用字符串从 routeParams 获取变量.

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

推荐答案

你不能像这样访问它:

$routeParams[$routeParams.title]

我想这就是你要问的,但我不太确定......

I think that is what you are asking, but I'm not quite sure...

这篇关于Angular 在页面标题中使用 $routeParams的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆