我所指的translateProvider像這樣:在angularJS服務如何我可以用MYPROVIDER
var myAppModule = angular.module('myapp', ['ngRoute', 'ngMaterial', 'ngResource', 'pascalprecht.translate']);
開始JS,我想用在我的commonService.js, 像這樣:
myAppModule.factory('commonService', ['$resource', '$translate', function ($resource, $translate) {
var auth = $resource('http://localhost:8012/user/auth.aspx', {}, {});
return {
init: function() {
var language = $resource("/Resources/Chinese.json");
language.get(function (data) {
console.data(data);
});
$translate.translations('en', {
HEADLINE: 'Hello there, This is my awesome app!',
INTRO_TEXT: 'And it has i18n support!'
})
.translations('de', {
HEADLINE: 'Hey, das ist meine großartige App!',
INTRO_TEXT: 'Und sie untersützt mehrere Sprachen!'
});
$translate.preferredLanguage('de');
},
submit: function (user) {
user.uk = "ad82544450d6fd3296878cbcd7a95d6b";
return auth.get(user);
}
}
}]);
但它警告我: 類型錯誤:未定義是不是Object.init功能 (commonService.js:14): 在Object.invoke(angular.js在新的(8 loginController.js): 4182 ) 在$ get.extend.instance(angular.js:8441) 在angular.js:7693 在的forEach(angular.js:331) 在nodeLinkFn(angular.js:7692) 在compositeLinkFn(angular.js :7075) 在publicLinkFn(angular.js:6954) 在angular.js:1451個 angular.js:9814 GET http://localhost:41251/Resources/Chinese.json 404(未找到)
發現太謝謝你了。 – 2015-03-19 06:12:41