我正在尝试编写基于this post的翻译服务,但我无法开始调试,因为我一直收到错误“错误:[ng:areq]参数'TranslationController'不是一个函数,未定义“。
我从我的其他控制器复制了这个结构,这个控制器运行得很好,我哪里出错了?
(部分app.js代码)
}).when('/Location', {
templateUrl: "Views/Location/Location.html",
controller: "TranslationController"
部分index.html代码 - 忽略格式错误的HTML
script type="text/javascript" src="js/TranslationService.js"></script
script type="text/javascript" src="js/TranslationController.js"></script
script type="text/javascript" src="js/angular/i18n/angular-locale_en.js"></script
TranslationController.js
angular
.module('app')
.controller('TranslationController', ['$scope', '$cookies', 'TranslationService', function($scope, $cookies, $TranslationService) {
$scope.translation;
var onSuccess = function (tx, r) {
$scope.$apply(function () {
$scope.translation = r;
});
$scope.init = function () {
$TranslationService.getTranslation(onSuccess, $scope, $cookies.lang);
}
$scope.init();
}]);
TranslationService.js
angular
.module('TDE')
.factory('TranslationService', ['$resource', function($resource) {
return {
Translations : function(fn) {
return getTranslation($resource, $scope, $cookies.lang);
}
};
this.getTranslation = function($resource, $scope, language) {
var languageFilePath = "js/translations/translation_" + language + ".json";
window.logger.logIt("language path = " + languageFilePath);
$resource(languageFilePath).get(function (data) {
$scope.translation = data;
})
}
}]);
部分location.html文件:
<label>{{translation._EXPERIMENTTITLE_}}</label>
答案 0 :(得分:0)
检查完代码后,似乎您忘记在 onSuccess 方法
之后添加&#39;}angular
.module('app')
.controller('TranslationController', ['$scope', '$cookies', 'TranslationService', function($scope, $cookies, $TranslationService) {
$scope.translation;
var onSuccess = function (tx, r) {
$scope.$apply(function () {
$scope.translation = r;
});
}// forgot to add this
$scope.init = function () {
$TranslationService.getTranslation(onSuccess, $scope, $cookies.lang);
}
$scope.init();
}]);