我在另一个 SO question 中找到了这个答案。但我也想在某些页面标题中使用路由参数。
如果我有$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 获取变量。