Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 无法将提供程序注入配置块_Angularjs_Dependency Injection - Fatal编程技术网

Angularjs 无法将提供程序注入配置块

Angularjs 无法将提供程序注入配置块,angularjs,dependency-injection,Angularjs,Dependency Injection,我无法在我的配置部分中注入提供程序,以下是我的代码: <!-- they are placed in that order --> <script src="app/components/department/DepartmentController.js"></script> <script src="app/components/department/DepartmentProvider.js">

我无法在我的配置部分中注入提供程序,以下是我的代码:

 <!-- they are placed in that order -->
            <script src="app/components/department/DepartmentController.js"></script>
            <script src="app/components/department/DepartmentProvider.js"></script>
            <script src="app/components/department/DepartmentService.js"></script>


            <script src="app/components/department/support/SupportController.js"></script>
            <script src="app/components/department/support/SupportRouter.js"></script>
DepartmentService.js:

departmentModule.factory('Department', function($http) {

            return {
                getAll : function(){
                        return $http.get('/api/departments');
                    },
                getByName : function(name){
                        return $http.get('/api/department/'+name);
                    }
                };

});
DepartmentProvider.js:

departmentModule.provider('Department', function() {
     var name = 'marwen';

     this.$get = function() {
         return {
            name: name
         };
     };
});
SupportRouter.js:

supportModule.config(function($stateProvider, $urlRouterProvider,$locationProvider,DepartmentProvider) {


我收到此错误:
未知提供程序:DepartmentProvider
尝试将
supportModule.config(函数($stateProvider,$urlRouterProvider,$locationProvider,DepartmentProvider)
更改为
supportModule.config(函数($stateProvider,$urlRouterProvider,$locationProvider,Department)


或者将您的提供商名称从
部门
更改为
部门提供商
部门
提供商已被
部门
服务覆盖,您需要为提供商和服务指定不同的名称,两者不能使用相同的名称,最新的提供商将获得注册。在加载服务时ice在提供者之后。服务在Angular应用程序中注册&提供者在配置中不可用。

我认为
部门
提供者已被
部门
工厂覆盖是的,Angular可能对名称不明确,但这不是我的问题,它特定于我的项目结构,因此代码保持不变问题是,奇怪的是,我删除了提供者,而我正在与工厂合作(我只是在“部门”后面加上了“提供者”)它现在可以工作了,所以我可以与提供者和服务一起工作?这是因为在配置阶段,提供者可以使用
提供者
后缀访问。除了配置块,它只能作为
部门
访问。因此,在这种情况下,
部门
服务被调用,而不是
部门
提供者..y你需要有不同的名字让他们使用
supportModule.config(function($stateProvider, $urlRouterProvider,$locationProvider,DepartmentProvider) {