Angular Translate:LocalStorage插件和requirejs错误

时间:2015-10-16 19:56:05

标签: javascript angularjs angular-translate

我将Angular与require.js结合使用。除此之外,我使用angular-translate插件。现在我添加了插件angular-translate-storage-local,我收到了此错误:Error: [$injector:unpr] Unknown provider: $translateCookieStorageProvider <- $translateCookieStorage <- $translateLocalStorage <- $translate

通常我会说我忘了添加依赖项,但我没有(我猜)!

我的requirejs.config

requirejs.config({
    shim: {
        angular: {
            exports: 'angular'
        },
        ngTranslateLoader: ['ngTranslate'],
        ngTranslateLocalStorage: ['ngTranslate']
    },

    paths: {
        ngTranslate: '../../vendor/angular-translate/angular-translate',
        ngTranslateLoader: '../../vendor/angular-translate-loader-static-files/angular-translate-loader-static-files',
        ngTranslateLocalStorage: '../../vendor/angular-translate-storage-local/angular-translate-storage-local'
    }
});

我的module

define(function(require) {
    require('ngTranslate');
    require('ngTranslateLocalStorage');
    require('ngTranslateLoader');

    var angular = require('angular');

    var app = angular.module('app', [
        'pascalprecht.translate'
    ])
        .config([$translateProvider', function ($translateProvider) {
            $translateProvider
                .useStaticFilesLoader({
                    prefix: '/language/',
                    suffix: '.json'
                })
                .preferredLanguage('en-DK')
                .useSanitizeValueStrategy('escape')
                .useLocalStorage();
        }]);
});

静态文件加载器插件运行良好。我的失败在哪里?

编辑: 我在我的requirejs配置中添加了以下内容:

ngTranslateLocalStorage: ['ngTranslateCookieStorage', 'ngTranslate'],
ngTranslateCookieStorage: ['ngCookies', 'ngTranslate'],
ngCookies: ['angular'],

现在我得到:Error: [$injector:unpr] Unknown provider: $cookieStoreProvider <- $cookieStore <- $translateCookieStorage <- $translateLocalStorage <- $translate

如果我理解requirejs shim正确,那么现在应该require(ngTranslateLocalStorage)就够了,但接着我得到pascalprecht.translate未知的消息。如果我需要所有deps,虽然它已经在垫片中完成,我得到上面的错误。还是有问题!?

1 个答案:

答案 0 :(得分:7)

服务$translateLocalStorage取决于$translateCookieStorage,而$cookieStore依赖于来自angular-cookies的{​​{1}}。

因此,您还需要包含angular-translate-storage-cookieangular-cookies,并在模块依赖项中添加ngCookies

总结你应该:

"angular-translate"
"angular-translate-loader-static-files"
"angular-cookies"
"angular-translate-storage-cookie"
"angular-translate-storage-local"