[英]Angular Js Access Title from $routeProvider on each View
Is there is any possible way to get the title attribute into header always when the route changed 路由更改时,是否有任何可能的方法始终将title属性获取到标题中
Example: 例:
when('/newsletter', {
title: 'News Letter',
templateUrl:'app/Views/segment/newsletter.html'
})
When this route comes the view is newsletter and i need to show the title as newsletter in Header Newsletter Tab 当这条路线到达时,视图就是新闻通讯,我需要在“标题新闻通讯”选项卡中将标题显示为新闻通讯
You can have a root scope variable named "title" and change it in your controller by doing $rootScope.title = 'new title';
您可以拥有一个名为“ title”的根范围变量,并通过执行$rootScope.title = 'new title';
在控制器中对其进行更改$rootScope.title = 'new title';
Or better, you can have this done in the resolve
option in router, for more information, please click: $routeProvider 或者更好的是,您可以在router的resolve
选项中完成此操作,有关更多信息,请单击: $ routeProvider
What you should do is to expose $route
service to the view in either main controller (topmost) or in run block (better): 您应该做的是在主控制器(最顶部)或运行块(更好)中将$route
服务公开给视图:
app.run(['$route', '$rootScope', function($route, $rootScope) {
$rootScope.$route = $route;
}]);
Then in any view you can display current title: 然后可以在任何视图中显示当前标题:
<header>
<h1>{{ $route.current.title }}</h1>
</header>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.