在状态参数上使用 angular-translate
Using angular-translate on state parameters
我正在使用 angular-translate
进行本地化,除了在状态参数内转换数据外,一切正常。
比如我有这样一个状态:
.state('about', {
url: "/about",
isAbstract: true,
template: '<ui-view/>',
data: {
title: 'About'
}
})
标题应该是翻译的重点。我试过 title: $filter('translate')('ABOUT')
但没用。
有什么想法可以做到吗?
您应该使用如下给定的语法
.run(function($rootScope, $translate) {
$rootScope.$on('$stateChangeStart', function(event, toState) {
if (toState.data.title) {
$translate(toState.data.title).then(function(translation) {
$rootScope.pageTitle = translation;
},
function() {
$rootScope.pageTitle = 'About';
});
}
});
})
查看示例 here
我正在使用 angular-translate
进行本地化,除了在状态参数内转换数据外,一切正常。
比如我有这样一个状态:
.state('about', {
url: "/about",
isAbstract: true,
template: '<ui-view/>',
data: {
title: 'About'
}
})
标题应该是翻译的重点。我试过 title: $filter('translate')('ABOUT')
但没用。
有什么想法可以做到吗?
您应该使用如下给定的语法
.run(function($rootScope, $translate) {
$rootScope.$on('$stateChangeStart', function(event, toState) {
if (toState.data.title) {
$translate(toState.data.title).then(function(translation) {
$rootScope.pageTitle = translation;
},
function() {
$rootScope.pageTitle = 'About';
});
}
});
})
查看示例 here