简体   繁体   English

错误:[$ injector:unpr]未知提供程序:someProvider <-SomeService

[英]Error: [$injector:unpr] Unknown provider: someProvider <- SomeService

In angularjs 在angularjs中

I have made sure to register a service like this, inside the services directory inside modules -> module_name 我已经确保在模块-> module_name中的services目录中注册这样的服务

angular.module('module_name').factory('service_name', [
    function() {
        // Public API
    console.log('hello');
        return {
            someMethod: function() {
                return true;
            }
        };
    }
]);

from this Error: Unknown provider: employeesProvider <- employees i found removing the ngController solves the issue, but I am trying to render a view that must have a controller to render some model data. 从此错误:未知提供者:employeeProvider <-员工,我发现删除ngController解决了此问题,但是我试图呈现必须具有控制器才能呈现某些模型数据的视图。

If i remove that ngController, i get no data. 如果我删除该ngController,则不会获得任何数据。

What do i do? 我该怎么办?

It looks like you have dependency on the employees module (somewhere not shown in your posted code). 看来您对employees模块有依赖性(在您的发布代码中未显示)。 You need to inject that into this module_name. 您需要将其注入到这个module_name中。

angular.module('module_name',['employees'])
.factory('service_name', ['employees', function(employees) {
    // Public API
    console.log('hello');
    return {
        someMethod: function() {
            return true;
        }
    };
}]);

The dependency could also be in your controller. 依赖关系也可能在您的控制器中。 You should use the similar method to inject the dependency there. 您应该使用类似的方法在其中注入依赖项。

Additional information on dependency injection . 有关依赖项注入的其他信息。

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

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