タイトルの角度ルートのオプションパラメータをどのように使用できますか。
だから私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;
}
}
タイトル文字列のルートパラメータにプレースホルダーを使用し、ルートパラメータオブジェクトに対して補間します。
.when('/search/:textToSearch', {
title: 'Searching {{ textToSearch }}',
templateUrl: 'views/search.html',
controller: 'searchController'
})
補間部分(必ず$interpolate
サービスを注入してください):
$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);
}
})
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加