我找到了这个 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/