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

查看:200
本文介绍了在页面标题使用角$ 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 是这样的:

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

但我不知道如何使用字符串来获得从routeParams的变量。

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

推荐答案

你就不能访问它是这样的:

Can't you just access it like this:

$routeParams[$routeParams.title]

我认为这是你问什么,但我不太清楚...

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

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

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