AngularJS 未知提供商 cookieReader
AngularJS unknown provider cookieReader
我正在尝试使用 AngularJS 翻译。我遇到的问题是在尝试使用 $translateProvider.useCookieStorage();
时出现 Unknown provider: $$cookieReaderProvider <- $$cookieReader <- $cookies <- $cookieStore <- $translateCookieStorage <- $translate <- $cookies
错误
我已将 ngCookies
作为依赖项注入到我的应用程序中:
var nfqApp = angular.module('myApp', ['postServices', 'angularFileUpload', 'ngSanitize', 'ui.date',
'bootstrapLightbox', 'profileServices', 'ngRoute', 'angularMoment', 'pascalprecht.translate', 'ngCookies']);
我还按以下顺序包含了以下与翻译和 cookie 相关的文件:
- angular-translate.min.js
- angular-cookies.js
- angular-翻译插值-messageformat.js
- angular-翻译存储-cookie.js
- messageformat.js
- en.js
- lt.js
我的应用程序配置(我尝试使用 cookieStorage 的地方:
myApp.config(['$translateProvider', function ($translateProvider) {
$translateProvider.translations('lt', {
"OTHER_LIKES" : "{peopleCount, plural, one {# kolega tai mėgsta} few {# kolegos tai mėgsta} other {# kolegų tai mėgsta}}",
"YOU_AND_OTHERS_LIKES" : "{peopleCount, plural, one {Tu ir # kolega tai mėgsta} few {Tu ir # kolegos tai mėgsta} other {Tu ir # kolegų tai mėgsta}}",
"YOU_LIKE" : "Tu mėgsti tai"
});
$translateProvider.translations('en', {
"OTHER_LIKES" : "{peopleCount, plural, one {# colleague likes this} few {# colleagues likes this} other {# colleagues likes this}}",
"YOU_AND_OTHERS_LIKES" : "{peopleCount, plural, one {You and # colleague likes this} few {You and # colleagues likes this} other {You and # colleagues likes this}}",
"YOU_LIKE" : "You like this"
});
$translateProvider.preferredLanguage('lt');
$translateProvider.fallbackLanguage('en');
$translateProvider.addInterpolation('$translateMessageFormatInterpolation');
$translateProvider.useCookieStorage();
}]);
我发现我使用的是为 angular 的不同版本设计的 angular-cookies.js。将它们更新为相同版本解决了问题。 AngularJS 使用了 v1.4.1。
我使用的是 Ionic 框架,ionic.bundle.js 中的 angular.js 是 1.3.6,但我的 angular-cookies 版本是 1.4.4
所以我降级了 angular-cookies 的版本,结果成功了。
bower install angular-cookies#1.3.6
我正在尝试使用 AngularJS 翻译。我遇到的问题是在尝试使用 $translateProvider.useCookieStorage();
Unknown provider: $$cookieReaderProvider <- $$cookieReader <- $cookies <- $cookieStore <- $translateCookieStorage <- $translate <- $cookies
错误
我已将 ngCookies
作为依赖项注入到我的应用程序中:
var nfqApp = angular.module('myApp', ['postServices', 'angularFileUpload', 'ngSanitize', 'ui.date',
'bootstrapLightbox', 'profileServices', 'ngRoute', 'angularMoment', 'pascalprecht.translate', 'ngCookies']);
我还按以下顺序包含了以下与翻译和 cookie 相关的文件:
- angular-translate.min.js
- angular-cookies.js
- angular-翻译插值-messageformat.js
- angular-翻译存储-cookie.js
- messageformat.js
- en.js
- lt.js
我的应用程序配置(我尝试使用 cookieStorage 的地方:
myApp.config(['$translateProvider', function ($translateProvider) {
$translateProvider.translations('lt', {
"OTHER_LIKES" : "{peopleCount, plural, one {# kolega tai mėgsta} few {# kolegos tai mėgsta} other {# kolegų tai mėgsta}}",
"YOU_AND_OTHERS_LIKES" : "{peopleCount, plural, one {Tu ir # kolega tai mėgsta} few {Tu ir # kolegos tai mėgsta} other {Tu ir # kolegų tai mėgsta}}",
"YOU_LIKE" : "Tu mėgsti tai"
});
$translateProvider.translations('en', {
"OTHER_LIKES" : "{peopleCount, plural, one {# colleague likes this} few {# colleagues likes this} other {# colleagues likes this}}",
"YOU_AND_OTHERS_LIKES" : "{peopleCount, plural, one {You and # colleague likes this} few {You and # colleagues likes this} other {You and # colleagues likes this}}",
"YOU_LIKE" : "You like this"
});
$translateProvider.preferredLanguage('lt');
$translateProvider.fallbackLanguage('en');
$translateProvider.addInterpolation('$translateMessageFormatInterpolation');
$translateProvider.useCookieStorage();
}]);
我发现我使用的是为 angular 的不同版本设计的 angular-cookies.js。将它们更新为相同版本解决了问题。 AngularJS 使用了 v1.4.1。
我使用的是 Ionic 框架,ionic.bundle.js 中的 angular.js 是 1.3.6,但我的 angular-cookies 版本是 1.4.4 所以我降级了 angular-cookies 的版本,结果成功了。
bower install angular-cookies#1.3.6