angularjs - Angular 在页面标题中使用 $routeParams

标签 angularjs angular-routing

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

如果我有 $routeProvider像这样:

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

我如何匹配 :name:name 的标题中在位置?我尝试了以下
.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 获取变量。

最佳答案

你不能像这样访问它:

$routeParams[$routeParams.title]

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

关于angularjs - Angular 在页面标题中使用 $routeParams,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20831660/

相关文章:

javascript - 为什么在 AngularJS 中设置服务时,数据没有从一个 Controller 更新到另一个 Controller ?

mysql - 使用旧的 generator-angular-fullstack 版本

css - 检查正在应用哪个 Bootstrap 类并根据使用 AngularJS 添加行为

javascript - 为什么 AngularJS 路由器不触发?

angular - 在 app.routing.module Angular 中使用服务

javascript - 如何在 ng-repeat 中对 JSON 数据进行排序?

javascript - 同时多次调用同一服务

javascript - 将 Firebase 记录 key 传递到 URL

angular - 在 Angular 2 router 3.0 中创建默认路由

angular-routing - Angular 2 辅助路由器坏了吗?