UI路由器动态&LT;标题&GT;标签 [英] UI Router dynamic <title> tag
本文介绍了UI路由器动态&LT;标题&GT;标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在那样的UI路由器添加标题到每个状态:
.STATE('项目',{
网址:'/',
templateUrl:项目/ projects.html',
ncyBreadcrumb:{
标签:'项目'
},
数据:{标题:'项目'}
})
然后是title属性需要的数据:
&LT;标题NG绑定=$ state.current.data.title&GT;&LT; /标题&GT;
我如何采取从状态参数数据,并在上面的例子中添加标题?我试过,没有运气以下内容:
.STATE('项目',{
摘要:真实,
网址:'/项目/:PROJID',
解决:{
PROJID:['$ stateParams',函数($ stateParams){
返回$ stateParams.projId;
}]
},
控制器:'projectCtrl',
templateUrl:项目/ project.html',
ncyBreadcrumb:{
标签:'工程',
家长:'项目'
},
数据:{标题:{{状态}}}
})
解决方案
您必须使用 app.run()在app.js文件,并在 $ rootScope分配您的标题。标题。你可以按照这个code
app.run(函数($ rootScope){
$ rootScope。在$('$ stateChangeStart',函数(事件,toState,toParams,fromState){ $ rootScope.title = toState.data.title;
});
});
在此之后则变量绑定在你的HTML像这样
&LT;标题NG绑定=标题&GT;&LT; /标题&GT;
我认为这将有所帮助。
I'm adding a title to every state in the ui-router like that:
.state('projects', {
url: '/',
templateUrl: 'projects/projects.html',
ncyBreadcrumb: {
label: 'Projects'
},
data : {title: 'Projects'}
})
And then the title attribute takes that data:
<title ng-bind="$state.current.data.title"></title>
How can I take data from the state parameters and add it to the title in the above example? I tried the following with no luck:
.state('project', {
abstract: true,
url: '/projects/:projId',
resolve:{
projId: ['$stateParams', function($stateParams){
return $stateParams.projId;
}]
},
controller: 'projectCtrl',
templateUrl: 'project/project.html',
ncyBreadcrumb: {
label: 'Project',
parent: 'projects'
},
data : {title: '{{state}}'}
})
解决方案
you have to use app.run() in your app.js file and assign your title in $rootScope.title . you can follow this code
app.run(function($rootScope){
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState){
$rootScope.title=toState.data.title;
});
});
after this then bind the variable in your html like this
<title ng-bind="title"></title>
I think it will helpful
这篇关于UI路由器动态&LT;标题&GT;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文