この答えは、別の 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 から変数を取得する方法がわかりません。