Angularjs 角度-在标题中使用可选参数
如何使用标题中我的角度路线中的可选参数 因此,我希望Angularjs 角度-在标题中使用可选参数,angularjs,Angularjs,如何使用标题中我的角度路线中的可选参数 因此,我希望textToSearch出现在标题中: .when('/search/:textToSearch', { title: 'Searching' + textToSearch, templateUrl: 'views/search.html', controller: 'searchController' } ) 我正在routeChangeSuccess中设置标题: $rootScope
textToSearch
出现在标题中:
.when('/search/:textToSearch',
{
title: 'Searching' + textToSearch,
templateUrl: 'views/search.html',
controller: 'searchController'
}
)
我正在routeChangeSuccess中设置标题:
$rootScope.$on('$routeChangeSuccess', function() {
//Set the <title> tag
if (!$route.current.title) {
document.title = 'Default Generic Title';
} else {
document.title = $route.current.title;
}
}
$rootScope.$on(“$routeChangeSuccess”,function()函数){
//设置标签
如果(!$route.current.title){
document.title='默认通用标题';
}否则{
document.title=$route.current.title;
}
}
我会在标题字符串中为路由参数使用占位符,并根据路由参数对象插入它:
.when('/search/:textToSearch', {
title: 'Searching {{ textToSearch }}',
templateUrl: 'views/search.html',
controller: 'searchController'
})
插入部分(确保插入$interpolate
服务):
$rootScope.$on(“$routeChangeSuccess”,function()函数){
//设置标签
如果(!$route.current.title){
document.title='默认通用标题';
}否则{
document.title=$interpolate($route.current.title)($route.current.params);
}
})
如何使用title
?像这样?是的,使用routeChangeSuccess-更新代码title:“搜索{{{textToSearch}}',
似乎不起作用,我测试过;)确保注入$interpolation服务。你有错误吗?啊,是的,忘记注入服务了!
$rootScope.$on('$routeChangeSuccess', function() {
//Set the <title> tag
if (!$route.current.title) {
document.title = 'Default Generic Title';
} else {
document.title = $interpolate($route.current.title)($route.current.params);
}
})