Angularjs 角度平移在控制器中的应用
我正在AngularJS应用程序中为i18n使用角度转换 代码:Angularjs 角度平移在控制器中的应用,angularjs,Angularjs,我正在AngularJS应用程序中为i18n使用角度转换 代码: angular .module('Test') .controller('AlertsCtrl', ['$translate', '$scope', AlertsCtrl]); function AlertsCtrl($translate, $scope) { // Api: http://angular-translate.github.io/docs/#/guide/03_using-translat
angular
.module('Test')
.controller('AlertsCtrl', ['$translate', '$scope', AlertsCtrl]);
function AlertsCtrl($translate, $scope) {
// Api: http://angular-translate.github.io/docs/#/guide/03_using-translate-service
$translate('ALERT_MSG_1', 'ALERT_MSG_2').then(function (line) {
$scope.alerts = [{
type: 'success',
msg: line['ALERT_MSG_1'] // Dosn't work
}, {
type: 'danger',
msg: line['ALERT_MSG_2'] // Dosn't work
}];
console.log("In");
});
console.log("--- " + $translate.instant('ALERT_MSG_2')); // Works
$scope.addAlert = function () {
$scope.alerts.push({
msg: 'Another alert!'
});
};
$scope.closeAlert = function (index) {
$scope.alerts.splice(index, 1);
};
}
问题:
angular
.module('Test')
.controller('AlertsCtrl', ['$translate', '$scope', AlertsCtrl]);
function AlertsCtrl($translate, $scope) {
// Api: http://angular-translate.github.io/docs/#/guide/03_using-translate-service
$translate('ALERT_MSG_1', 'ALERT_MSG_2').then(function (line) {
$scope.alerts = [{
type: 'success',
msg: line['ALERT_MSG_1'] // Dosn't work
}, {
type: 'danger',
msg: line['ALERT_MSG_2'] // Dosn't work
}];
console.log("In");
});
console.log("--- " + $translate.instant('ALERT_MSG_2')); // Works
$scope.addAlert = function () {
$scope.alerts.push({
msg: 'Another alert!'
});
};
$scope.closeAlert = function (index) {
$scope.alerts.splice(index, 1);
};
}
行['ALERT_MSG_1']和行['ALERT_MSG_2']没有返回任何信息。为什么?
如何解决这个问题?如果要翻译多个字符串,应该使用数组。i、 e
$translate(['ALERT_MSG_1', 'ALERT_MSG_2']).then(function (line) {
$scope.alerts = [{
type: 'success',
msg: line['ALERT_MSG_1'] // Dosn't work
}, {
type: 'danger',
msg: line['ALERT_MSG_2'] // Dosn't work
}];
console.log("In");
});