拦截器中依赖注入的错误

时间:2016-01-12 16:58:30

标签: javascript angularjs dependency-injection

我有三个文件app.js,common.services.js和tokenContainer.js。当我试图将tokenContainer依赖注入app.js的拦截器时,我收到一个错误:

未捕获错误:[$ injector:unpr]未知提供者:tokenContainerProvider< - tokenContainer< - $ http< - $ templateRequest< - $ compile

common.service.js文件

(function () {
        "use strict";

        angular
            .module("common.services",
                        ["ngResource"])
            .constant("appSettings",
            {
                serverPath: "http://localhost:6359"
            });
    }());

tokenContainer.js文件:

(function () {
    "use strict";

    angular
        .module("common.services")
        .factory("tokenContainer",
                  [tokenContainer])

    function tokenContainer() {

        var container = {
            token: ""
        };

        var setToken = function (token) {
            container.token = token;
        };

        var getToken = function () {

        };

        return {
            getToken: getToken
        };
    };

})();

app.js文件:

(function () {

    var app = angular.module("productManagement",
                            ["ngRoute", "common.services"]);

    app.config(function ($routeProvider, $httpProvider) {

        $routeProvider
            .when("/products", {
                templateUrl: "app/products/productListView.html",
                controller: "ProductListCtrl as vm"
            })
            .when("/products/create", {
                templateUrl: "app/products/productCreateView.html",
                controller: "ProductCreateCtrl as vm"
            })
            .when("/login", {
                templateUrl: "app/login/login.html",
                controller: "loginController as vm"
            })
           .otherwise({ redirectTo: "/products" });

        $httpProvider.interceptors.push(function (appSettings, tokenContainer) {
            return {
                'request': function (config) {
                    // ToDo :             
                    return config;
                }

            };
        });

    });

}());

0 个答案:

没有答案