简体   繁体   English

Angularjs [$ injector:unpr]未知的提供程序外部模块

[英]Angularjs [$injector:unpr] Unknown provider external module

i have a project that consists of modular angularjs sub apps. 我有一个包含模块化angularjs子应用程序的项目。 Sub apps reside in their own folders relative the root app folder. 子应用程序位于相对于根应用程序文件夹的自己的文件夹中。 The problem is that i want to include an external module (satellizer) via bower. 问题是我想通过凉亭包括一个外部模块(卫星化器)。 The module has downloaded correctly and the bower components get injected to the html via gulp/wiredep. 该模块已正确下载,并且Bower组件通过gulp / wiredep注入了html。 All good so far. 到目前为止一切都很好。

The structure of an app with a controller is as follows: 带有控制器的应用程序的结构如下:

(function () {
'use strict';

angular
    .module('foo.bar')
    .filter('orderObjectBy', function () {
        return function (input, attribute) {
            if (!angular.isObject(input)) return input;

            var array = [];
            for (var objectKey in input) {
                array.push(input[objectKey]);
            }

            array.sort(function (a, b) {
                a = parseInt(a[attribute]);
                b = parseInt(b[attribute]);
                return a - b;
            });
            return array;
        }
    })
    .controller('FoobarController', FoobarController);

FoobarController.$inject = ['logger', '$q', 'dataservice', '$stateParams', 'fooBarHandler', '$location', 'satellizer'];
/* @ngInject */
function FoobarController(logger, $q, dataservice, $stateParams, fooBarHandler, $location, $authProvider) {
    var vm = this;
    fooBarHandler.includeIn(vm, dataservice);

    vm.authorize = authorize;


    }        
}

Problem is that angular keeps saying that satellizer is an unknown provider (Unknown provider: satellizerProvider <- satellizer <- FooBarController) for the sake of brevity i omitted a lot of code from the controller implementation. 问题是,为简洁起见,Angular一直在说satellizer是未知提供程序(Unknown provider:satellizerProvider <-satellizer <-FooBarController),我省略了控制器实现中的许多代码。

i also tried to wire up the dependency via array dependency like so: 我还尝试通过数组依赖关系来连接依赖关系,如下所示:

 angular
    .module('foo.bar', ['satellizer'])
    .filter('orderObjectBy', function () {
        return function (input, attribute) {
            if (!angular.isObject(input)) return input;

            var array = [];
            for (var objectKey in input) {
                array.push(input[objectKey]);
            }

            array.sort(function (a, b) {
                a = parseInt(a[attribute]);
                b = parseInt(b[attribute]);
                return a - b;
            });
            return array;
        }
    })

but still no luck. 但仍然没有运气。

Got it working. 得到它的工作。 After digging trough the source of satellizer i realized i needed to inject from a provider. 在挖槽卫星源之后,我意识到我需要从提供商那里注入。 Satellizer has defined it's provider as '$auth'. Satellizer已将其提供程序定义为“ $ auth”。 So after i changed the line 所以我换线后

FooBarController.$inject = ['logger', '$q', 'dataservice', '$stateParams', 'fooBarHandler', '$location', 'satellizer];

to

FooBarController.$inject = ['logger', '$q', 'dataservice', '$stateParams', 'fooBarHandler', '$location', '$auth];

it worked 有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM